error C2784: Could not deduce template argument
Posted
by atch
on Stack Overflow
See other posts from Stack Overflow
or by atch
Published on 2010-03-16T13:50:10Z
Indexed on
2010/03/16
14:26 UTC
Read the original article
Hit count: 505
Hi guys,
Still fighting with templates. In this example, despite the fact that is copied straight from a book I'm getting the following error message: Error 2 error C2784: 'IsClassT<T>::One IsClassT<T>::test(int C::* )' : could not deduce template argument for 'int C::* ' from 'int'.
This is an example from a book Templates - The Complete Guide. (I work with Visual Studio 2010 RC).
template<typename T>
class IsClassT {
private:
typedef char One;
typedef struct { char a[2]; } Two;
template<typename C> static One test(int C::*);
template<typename C> static Two test(…);
public:
enum { Yes = sizeof(IsClassT<T>::test<T>(0)) == 1 };
enum { No = !Yes };
};
class MyClass {
};
struct MyStruct {
};
union MyUnion {
};
void myfunc()
{
}
enum E {e1} e;
// check by passing type as template argument
template <typename T>
void check()
{
if (IsClassT<T>::Yes) {
std::cout << " IsClassT " << std::endl;
}
else {
std::cout << " !IsClassT " << std::endl;
}
}
// check by passing type as function call argument
template <typename T>
void checkT (T)
{
check<T>();
}
int main()
{
/*std::cout << "int: ";
check<int>(); */
std::cout << "MyClass: ";
check<MyClass>();
}
And although I know roughly what's going on in this example I cannot fix this error.
Thanks for help.
© Stack Overflow or respective owner