Last active
August 29, 2019 01:52
-
-
Save amullins83/42e3d544fe0d7a6bcbdcfbec6066d6df to your computer and use it in GitHub Desktop.
Define a Pure Virtual Method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#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