class Base class Derived public std string toString return std string

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Base
{
};
class Derived
{
public:
std::string toString(){ return std::string("Derived"); }
};
template<typename T>
class Test
{
public:
Test(T &obj):_obj(obj){}
void execute(){ std::cout << _obj.toString() << std::endl; }
}
int main()
{
Derived obj;
Test<Derived> test(obj);
test.execute()
return 0;
}