Skip to content

Instantly share code, notes, and snippets.

@iarash84
Created March 7, 2023 06:48
Show Gist options
  • Save iarash84/46a63831b45516d039356591c7c92f3e to your computer and use it in GitHub Desktop.
Save iarash84/46a63831b45516d039356591c7c92f3e to your computer and use it in GitHub Desktop.
virtual function exmaple
class Shape {
public:
virtual void draw() {
std::cout << "Drawing a shape\n";
}
};
class Circle : public Shape {
public:
void draw() override {
std::cout << "Drawing a circle\n";
}
};
int main() {
Shape* shapePtr = new Circle();
shapePtr->draw(); // Output: "Drawing a circle"
delete shapePtr;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment