I'm trying to work with interfaces
class IDemo
{
public:
virtual ~IDemo() {}
virtual uint32_t Some_Operation(uint32_t a, uint32_t b) = 0;
};
class Child_A : public IDemo
{
public:
virtual uint32_t Some_Operation(uint32_t a, uint32_t b);
};
class Child_B : public IDemo
{
public:
virtual uint32_t Some_Operation(uint32_t a, uint32_t b);
};
Child_A::Some_Operation returns the sum of a+b Child_B::Some Operation return the product a*b
The usage is as follows
bool Test_Inferface()
{
IDemo* pDemo = new Child_B();
uint32_t product = pDemo->Some_Operation(1, 2);
delete pDemo;
if (2 != product)
{
return false;
}
pDemo = new Child_A();
uint32_t sum = pDemo->Some_Operation(1,2);
delete pDemo;
if(3 != sum)
{
return false;
}
return true;
}
I'm trying to avoid new/delete because of possible memory leaks. Is it possible to statically allocate the interface?
IDemo test = Child_A();
The compiler does not like that.