OOP problem (c++)

Started by
4 comments, last by Zahlman 18 years, 1 month ago
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.

class ClassB
{
   public:
      void function();
};

class ClassA
{
   public:
      ClassB member;
      void validate(void (*pfn)());
};

int main()
{
   ClassA classA;
   classA.validate(classA.member.function);
}



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.
Simplicity is the ultimate sophistication. – Leonardo da Vinci
Advertisement
Is this native or managed?

Dave
native
Simplicity is the ultimate sophistication. – Leonardo da Vinci
You cannot pass a member function to a normal function pointer. They're different beasts. function-pointer.org for the gory details.
Thanks for the link. It seems to be just what I was lookin for.
Simplicity is the ultimate sophistication. – Leonardo da Vinci
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