Add example of visitor pattern in C++

This commit is contained in:
2021-05-11 20:56:05 -04:00
parent 53ee3df451
commit 8177d4c191
5 changed files with 132 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
#include <iostream>
#include "visitor.hpp"
int main(const int argc, const char * argv[])
{
Gear *newGear = new Gear(1.5f, 1.0f);
PartVisitor *newVisitor = new PartVisitor;
// Test visiting the Gear concrete component with PartVisitor
newGear->accept(newVisitor);
// Testing a Spring concrete component on the same visitor
auto *newSpring = new Spring(2.5f, 5.0f);
newSpring->accept(newVisitor);
}