C
Chang PilHun
#include <iostream>
using namespace std;
template<class T>
class B1
{
public:
void SayHi()
{
T* pT = static_cast<T*>(this);
pT->PrintClassName();
}
protected:
void PrintClassName()
{
cout << "This is B1";
}
};
class D1ublic B1<D1>
{
//No overridden function at all
};
class D2ublic B1<D2>
{
protected:
void PrintClassName()
{
cout << "This is D2";
}
}
;
main()
{
D1 d1;
D2 d2;
d1.SayHi();
d2.SayHi();
}
--------compiler said
test.cpp: In member function `void B1<T>::SayHi() [with T = D2]':
test.cpp:43: instantiated from here
test.cpp:32: `void D2:rintClassName()' is protected
test.cpp:12: within this context
why?
I never called this function.
.... Just.... c++'s philosophy?
using namespace std;
template<class T>
class B1
{
public:
void SayHi()
{
T* pT = static_cast<T*>(this);
pT->PrintClassName();
}
protected:
void PrintClassName()
{
cout << "This is B1";
}
};
class D1ublic B1<D1>
{
//No overridden function at all
};
class D2ublic B1<D2>
{
protected:
void PrintClassName()
{
cout << "This is D2";
}
}
;
main()
{
D1 d1;
D2 d2;
d1.SayHi();
d2.SayHi();
}
--------compiler said
test.cpp: In member function `void B1<T>::SayHi() [with T = D2]':
test.cpp:43: instantiated from here
test.cpp:32: `void D2:rintClassName()' is protected
test.cpp:12: within this context
why?
I never called this function.
.... Just.... c++'s philosophy?