Instance of an object isn't visible outside the current scope(f. e. OnButton1Click) Topic is solved

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
DonQ104
In need of some credit
In need of some credit
Posts: 4
Joined: Thu Feb 20, 2020 5:37 pm

Instance of an object isn't visible outside the current scope(f. e. OnButton1Click)

Post by DonQ104 » Fri Feb 21, 2020 6:33 pm

So I'm making an app which i described here: viewtopic.php?f=1&t=46861. I linked both projects but my problem is when i want to use one of the methods on object which i created. I can only use them in the scope where the object where created. I cant use anything for example OnButtonClick because i got compiler error that the object wasn't declared in this scope. So here is my main question; Where i need to create my object to be visible from all places? I tried to create the object and MYSQL variable in OnInit place and also in Frame Constructor but always get the same error. I'am using Win 10, CodeBlock 17.12 and wxWidgets 3.0.4 with wxSmith

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4265
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Instance of an object isn't visible outside the current scope(f. e. OnButton1Click)

Post by ONEEYEMAN » Fri Feb 21, 2020 9:42 pm

Hi,
Your question is really vague.
Could you post some code and the exact error message?

And also explain in layman terms what you are trying to achieve.

Thank you.

DonQ104
In need of some credit
In need of some credit
Posts: 4
Joined: Thu Feb 20, 2020 5:37 pm

Re: Instance of an object isn't visible outside the current scope(f. e. OnButton1Click)

Post by DonQ104 » Sat Feb 22, 2020 8:18 am

Ok, so here is the code:https://pastebin.com/2RwPiFKb
And error message C:\Users\User\Desktop\Shel\GUI\GUIMain.cpp|165|error: 'Sunshine' was not declared in this scope|
I commented hints in code to help you interpret my problem

User avatar
doublemax
Moderator
Moderator
Posts: 14992
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Instance of an object isn't visible outside the current scope(f. e. OnButton1Click)

Post by doublemax » Sat Feb 22, 2020 8:40 am

Code: Select all

    Shelter Sunshine;
    MYSQL* conn;
These are local variables, they exist only while the method/function is executed and will be destroyed at the end. You need to turn them into member variables of GUIFrame.

Code: Select all

#include "C:\Users\User\Desktop\Shel\Console\Shelter.h" //----need to give direct path because otherwise compiler cant see this
#include "C:\Users\User\Desktop\Shel\Console\Shelter.cpp" //----this is weird but without this compiler cant refer to constructor or 
Unrelated, but these two lines look fishy. You need to get rid of these problems.
Use the source, Luke!

Post Reply