[SOLVED] variable scope
-
hi
in my button.h file i have this:
private: int size;
and in my button.cpp file i have this code:
int getSize() { return size; }
the problem that drives me nuts is that when i try to build, i get an error " 'size' was not declared in this scope" on the 'return size;' line. what am i doing wrong? i declare the variable in the header, so why is it 'not declared in this scope'?
-
Hi
is that a member of a class?
int size; I meanthen syntax is:
int SomeClass::getSize() {
return size;
}else it just a normal function and it doesn't know any size to return as its not defined in the function or as global.
Note: SomeClass is the class that "int size" is defined in.
-
@mrjj said:
Hi
is that a member of a class?
int size; I meanthen syntax is:
int SomeClass::getSize() {
return size;i added the class name and now it works. thanx.
-
@harry
super. please mark it SOLVED if possible :)