Jan 5, 2014 at 1:49am UTC
You can name them whatever you want, though
getXX and
setXX (where
XX represents the variable name) are among the more commonly used names.
They're otherwise just like any other member function:
1 2 3 4 5 6 7 8
class myClass
{
private :
int foo;
public :
int getFooOrWhateverOtherFunctionNameYouChoose() const { return foo; }
void setFooOrPickSomeOtherNameThatMakesSenseOrBananas(int x) { foo = x; } // Preferably not bananas
};
http://www.cplusplus.com/doc/tutorial/classes/
Last edited on Jan 5, 2014 at 1:50am UTC
Jan 5, 2014 at 2:13am UTC
its not what i am looking for
i wana have this
C *a = new C();
a.X = 1;
and not
C *a = new C();
a.X(1);
note that X is a function (of some kind thats what i dont know) and not a variable
Jan 5, 2014 at 2:41am UTC
found it
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
struct S {
int i;
void putprop(int j) {
i = j;
}
int getprop() {
return i;
}
__declspec(property(get = getprop, put = putprop)) int the_prop;
};
int main() {
S s;
s.the_prop = 5;
return s.the_prop;
}
Last edited on Jan 5, 2014 at 2:41am UTC
Jan 5, 2014 at 4:11am UTC
Hmm, well, that appears to be Microsoft-specific, so don't expect that to work on other compilers.