Sign in to follow this  
gah_ribaldi

C++ classes - passing member functions by reference

Recommended Posts

How can I address this problem: I have a main class, Class1 which is a singleton and contains a class Class2. Class 2 needs to use a function from Class1, so I'm trying to come up with a way to make Class2 aware of the function inside Class1. My thoughts at the moment are that Class2 could contain a static pointer. This could then be set to point to the function I need in Class1, possibly at some point in the constructor of Class1. I'm not really sure how to implement that though. How would I do this? Or is there perhaps a better way to achieve this? Cheers

Share this post


Link to post
Share on other sites
Quote:

How would I do this? Or is there perhaps a better way to achieve this?

Almost certainly. But you haven't really said what it is you're trying to achieve. Why does Class2 have to be contained in Class1? Why does Class2 need a function from Class1?

(And let's not even go into the singleton thing)

Try explaining what it is you want to achieve, rather than how you're currently planning on doing it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this