class ClassB
{
public:
void function();
};
class ClassA
{
public:
ClassB member;
void validate(void (*pfn)());
};
int main()
{
ClassA classA;
classA.validate(classA.member.function);
}
OOP problem (c++)
Ok I have a class (lets call the first class ClassA)that has another class (ClassB) as its member. I made it so ClassB has a member function that has to be validated by a ClassA funtion (Im starting to think this wasnt as smart as I thought it would be). Anyway I figured I could pass a pointer, that points to the ClassB function, into the ClassA function. Incase Ive lost you already heres an illustration.
When I do that I get a error saying Im not passing the right kind of argument. I tried alot of different things like casts and using the & operater but I just got more errors. Can anyone tell me the right way to do this? Mabey my OOP design sucks if I even have this problem. Is there a way I can Access ClassA data members from within ClassB methods? if so I wouldnt have to pass pointers around.
You cannot pass a member function to a normal function pointer. They're different beasts. function-pointer.org for the gory details.
This structure looks pretty suspicious to me, especially in an "OOP" context. What are you hoping to accomplish?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement