Jump to content
  • Advertisement
Sign in to follow this  
ForeverNoobie

OOP problem (c++)

This topic is 4487 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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!