Add example of visitor pattern in C++
This commit is contained in:
16
cpp/patterns/visitor/main.cpp
Normal file
16
cpp/patterns/visitor/main.cpp
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user