class holder
{
public:
template<class T>
T get()
{
#if (typeid(T) == typeid(object1)){
return obj1;
}
#elif (typeid(T) == typeid(object2)){
return obj2;
}
// #else{
// return nullptr; // sory my mistake. ignore it.
// }
#endif
}
private:
object1 obj1;
object2 obj2;
}
Want get a object by templete, But, it not work. why and how to modify it.? I know Use it like this:
holder a;
object1 obj1 = a.get<object1>();