I would like to define a class that accept the pointer to it’s parent class as an Argument, but would it be possible to somehow pass it without needing to pass it directly such as:
class Child
{
public:
Child(Parent* hiddenArg);
};
class Parent
{
public:
Child myChild;
};
I know this is weird, but I am making my own Signal/Slot implementation and Child would be a signal defined, but I would like to get the parent so I can use it’s Event Dispatcher…
You can’t do it automatically, but all you need to do is construct
myChildin the Parent constructor like this:Note some compilers will emit a warning for that code: it thinks you’re using the
thispointer before the Parent class is fully constructed. As long as you only store the pointer in the Child constructor and don’t use it, you’re OK. You may legitimately want to disable the warning (try not to disable warnings project-wide though – just around the affected area).