Created
April 22, 2016 06:38
-
-
Save chrisdembia/6b675579ac76b6cd16bba59586a8f070 to your computer and use it in GitHub Desktop.
component_forward_declare_connector.cpp
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 AbstractConnector { | |
public: | |
virtual std::string getTypeName() const = 0; | |
}; | |
template <typename T> | |
class Connector : public AbstractConnector { | |
public: | |
std::string getTypeName() const override { | |
return T::getClassName(); | |
} | |
}; | |
class Component { | |
public: | |
virtual void VIRTUAL() = 0; | |
protected: | |
template <typename T> int constructConnector() { | |
aconn = new Connector<T>(); | |
return 0; | |
} | |
private: | |
AbstractConnector* aconn; | |
}; | |
class Bar; | |
class Foo : public Component { | |
public: | |
virtual void VIRTUAL() {} | |
//int z { constructConnector<Bar>() }; | |
void constructConnector_bar() { | |
constructConnector<Bar>(); | |
} | |
static std::string getClassName() { return "Foo"; } | |
}; | |
/* | |
class Bar : public Component { | |
public: | |
virtual void VIRTUAL() {} | |
int x { constructConnector<Foo>() }; | |
static std::string getClassName() { return "Bar"; } | |
}; | |
*/ | |
int main() { | |
cout << "hello " << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment