How do I setup a class that represents
an interface? Is this just an abstract base class?
Wednesday, 27 December 2017
inheritance - How do you declare an interface in C++?
Answer
To expand on the answer by href="https://stackoverflow.com/questions/318064/how-do-you-declare-an-interface-in-c#318084">bradtgmurray,
you may want to make one exception to the pure virtual method list of your interface by
adding a virtual destructor. This allows you to pass pointer ownership to another party
without exposing the concrete derived class. The destructor doesn't have to do anything,
because the interface doesn't have any concrete members. It might seem contradictory to
define a function as both virtual and inline, but trust me - it
isn't.
class
IDemo
{
public:
virtual ~IDemo()
{}
virtual void OverrideMe() = 0;
};
class
Parent
{
public:
virtual
~Parent();
};
class Child : public Parent,
public IDemo
{
public:
virtual void
OverrideMe()
{
//do stuff
}
};
You
don't have to include a body for the virtual destructor - it turns out some compilers
have trouble optimizing an empty destructor and you're better off using the default.
php - file_get_contents shows unexpected output while reading a file
I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...
-
I have an app which needs a login and a registration with SQLite. I have the database and a user can login and register. But i would like th...
-
I got an error in my Java program. I think this happens because of the constructor is not intialized properly. My Base class Program public ...
-
I would like to use enhanced REP MOVSB (ERMSB) to get a high bandwidth for a custom memcpy . ERMSB was introduced with the Ivy Bridge micro...
No comments:
Post a Comment