Semantics - Passing in an implemented interface into methods

Viewed 169

Consider the following interface:

class MyInterface
{
   virtual bool test(void * param) = 0;
}

Can do something like this to implement the interface?

MyInterfacemyInterface = new MyInterface()
{
   bool test(void * param)
   {
        return true;
   }
}

myClass.setInterface(myInterface);

----- OR -----

myClass.setInterface( new MyInterface()
{
   bool test(void * param)
   {
        return true;
   }
} );

PS: This method is done in Java. Wondering the something similar exsts in C++.

4 Answers
Related