const functions not compiling in, imp from singleton ifc
Posted: Thu May 03, 2012 9:53 am
When I compile the following code, the functions implemented by SingletonImplementation seem to be optimized out of the build because they are never being called. Even though my SingletonImplementation::createInstance() is creating a new SingletonImplementation, the functions of its parent class are being invoked when I issue:
Am I just being retarded here? I can't figure out wtf is going onnnnn. Here's the code:
Please help! Thanks in advance.
Code: Select all
SingletonInterface::getInstance()->iAreNotWorkingLol()
Code: Select all
// SingletonInterface.h
class SingletonInterface
{
public:
static SingletonInterface* getInstance() { return instance; }
virtual bool iAreNotWorkingLol() const { return true; }
protected:
static SingletonInterface* instance;
};
Code: Select all
// SingletonImplementation.h
class SingletonImplementation : public SingletonInterface
{
public:
static void createInstance();
bool iAreNotWorkingLol() const;
};
Code: Select all
// SingletonImplementation.cpp
void SingletonImplementation::createInstance()
{
if(!instance) instance = (SingletonInterface*)(new SingletonImplementation());
}
bool SingletonImplementation::iAreNotWorkingLol() const
{
return false;
}
Code: Select all
// main.cpp
SingletonImplementation::createInstance();