CANdevStudio
Development tool for CAN bus simulation
Loading...
Searching...
No Matches
VisitableWith< Visitor > Struct Template Referenceabstract

#include <visitablewith.h>

Public Member Functions

virtual void visit (Visitor &visitor)=0
 
virtual ~VisitableWith ()=default
 

Detailed Description

template<class Visitor>
struct VisitableWith< Visitor >

Example for two types that can be visited: A, B and visitor V.

struct V
{
void operator()(A&) { std::cout << "A\n"; }
void operator()(B&) { std::cout << "B\n"; }
};
struct A : VisitableWith<V>
{
void visit(V& v) override { v(*this); }
virtual ~A() = default;
};
struct B : VisitableWith<V>
{
void visit(V& v) override { v(*this); }
virtual ~B() = default;
};
int main()
{
A a;
B b;
V v;
using W = VisitableWith<V>;
W& va = a;
W& vb = b;
va.visit(v);
vb.visit(v);
}
int main(int argc, char *argv[])
Definition common_test.cpp:652
Definition visitablewith.h:49

gives

A B

Constructor & Destructor Documentation

◆ ~VisitableWith()

template<class Visitor >
virtual VisitableWith< Visitor >::~VisitableWith ( )
virtualdefault

Member Function Documentation

◆ visit()

template<class Visitor >
virtual void VisitableWith< Visitor >::visit ( Visitor visitor)
pure virtual

The documentation for this struct was generated from the following file: