Main > Software Forum
Help requested: C++ member function pointers
youki:
declare the member as static :
static int member_int;
screaming:
member_int isn't declared static, so accessing it without instantiating ExampleClass won't work.
screaming:
Out of curiosity, why are you doing this?
--- Code: ---void SetFoo(void)
{
member=&ExampleClass::foo; // <----------------error here
}
--- End code ---
Since this is the part that's causing you all this headache, are you sure there's no other way to do it?
max8061:
--- Quote from: screaming on September 19, 2006, 11:45:24 am ---Out of curiosity, why are you doing this?
--- End quote ---
Free homework help on BYOAC? :laugh2:
Buddabing:
Declaring member_int as static gives me linkage errors: "undefined reference to ExampleClass::member_int".
There are always alternate ways of doing this kind of thing. I could make member_int a global variable, or a static external to the class, or I could use a construct such as:
enum
{
FOO,
BAR
};
switch (state)
{
case FOO:
return foo();
break;
case BAR:
return bar();
break;
}
But that's not very elegant.
It is not strictly necessary to use the function pointers like I am doing. But that's what I want to do.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version