Skip to content

Instantly share code, notes, and snippets.

@amullins83
Last active August 29, 2019 01:52
Show Gist options
  • Save amullins83/42e3d544fe0d7a6bcbdcfbec6066d6df to your computer and use it in GitHub Desktop.
Save amullins83/42e3d544fe0d7a6bcbdcfbec6066d6df to your computer and use it in GitHub Desktop.
Define a Pure Virtual Method
#include <iostream>
using namespace std;
class Abstract
{
public:
virtual void DoStuff() = 0;
};
void Abstract::DoStuff()
{
cout << "You can do stuff" << endl;
}
class Concrete : public Abstract
{
public:
void DoStuff()
{
Abstract::DoStuff();
}
};
int main()
{
Concrete c;
//Abstract a; // Won't compile
c.DoStuff();
return 0;
}
@amullins83
Copy link
Author

#Define a Pure Virtual Method

Today I learned that C++ doesn't care if you define a pure virtual method and call it from a child class. It's still considered an abstract class, so you can't instantiate it directly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment