Since the constructor of classA is called before classB, the only chance you have is to create a init() method and call it from the classB constructor.
#include <QtGui>
class classA
{
public:
classA()
{
init(); // or don't call it if classA is abstract
}
virtual void init()
{
qWarning() << Q_FUNC_INFO;
foo();
}
virtual void foo()
{
qWarning() << Q_FUNC_INFO;
}
};
class classB : public classA
{
public:
classB() : classA()
{
init();
}
virtual void foo()
{
qWarning() << Q_FUNC_INFO;
}
};
int main(int argc, char *argv[])
{
classB b;
return 0;
}
#include <QtGui>
class classA
{
public:
classA()
{
init(); // or don't call it if classA is abstract
}
virtual void init()
{
qWarning() << Q_FUNC_INFO;
foo();
}
virtual void foo()
{
qWarning() << Q_FUNC_INFO;
}
};
class classB : public classA
{
public:
classB() : classA()
{
init();
}
virtual void foo()
{
qWarning() << Q_FUNC_INFO;
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
classB b;
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks