Приветствую всех
1.
int Method() { return 0; }
template<class T>
class CCallMethod : public T
{
public:
int CallMethod() { return Method(); }
};
template<class T>
int CallMethod(T* p)
{
return static_cast<CCallMethod<T>*>(p)->CallMethod();
}
class CClass
{
public:
int Method() { return 10; }
};
...
void main()
{
CClass c;
int n = CallMethod(&c);
// n == 10 - всё прекрасно
}
2.
int Method() { return 0; }
template<class T>
class CCallMethod : public T
{
public:
static int CallMethod() { return Method(); }
};
template<class T>
int CallMethod()
{
return CCallMethod<T>::CallMethod();
}
class CClass
{
public:
static int Method() { return 10; }
};
void main()
{
int n = CallMethod<CClass>();
// n == 0. Почему ??? :(
};
Кто знает глубоко подобные детали, скажите мне, почему во втором случае вызывается глобальный Method() а не static CClass::Method(), хотя если Method() — нестатический, то всё работает нормально ???
Chez, ICQ# 161095094