• Advertisement
Sign in to follow this  

OOP problem (c++)

This topic is 4310 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
This structure looks pretty suspicious to me, especially in an "OOP" context. What are you hoping to accomplish?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement