I have a: header.cpp, header.hpp and a test_header.cpp.
In header.hpp i've i have:
class MyClass
{
public;
MyClass();
std::string name;
//...code with other variables,methods;
class MySecondClass
{
public:
MySecondClass();
std::string surname;
//..code with other variables,methods
}*MySC;
public:
template<class T>
bool method(T& obj);
{
if (typeid(MyClass)=typeid(obj))
{
MyClass *s= new MyClass();
*s=obj //i want to save everything that i have in obj into s;
//call method "MyMethod" and work with s
}
else if (typeid(MyClass::MySecondClass)=typeid(obj))
{
MyClass::MySecondClass *s1= new MyClass::MySecondClass();
*s1 = obj;
//call "MyMethod" and work with s1;
}
return true;
}
}*mycls;
In test_header.cpp I have
{
MyClass *mycls = new MyClass();
MyClass::MySecondClass *mysec_cls= new MyClass::MySecondClass();
if (mycls->method<MyClass>(*mycls)
{//code
}
if (mycls->method<MyClass::MySecondClass>(*mysec_cls)
{//code
}
}
I have an error saying that mysec_cls is not of type MyClass. As i've realised the pointer goes to the first if and never on else.
.h error: no match for operator= in *s1 = obj.
note: candidates are: MyClass& MyClass::operator=(const MyClass&)
I don't have this error if in test_header.cpp i have just one if and if in template i only have the reference from the if in test_header, but if ihave more than one refference to T& obj i have the error i've mentioned.
Why? how to change this? i am compiling using g++.