Hi guys,
I had a problem by using microsoft visual C++ 6.0 to compiling a simple code. using template function in a class seems not work.
Everything works fine by using g++ compiler.
Does anyone have some solution for this problem?
Thanks in advance.
Liwen
The error message as following
Compiling...
testit.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\tmp\testit.cpp(26) : error C2275: 'u8_t' : illegal use of this type as an expression
C:\Program Files\Microsoft Visual Studio\MyProjects\tmp\testit.cpp(4) : see declaration of 'u8_t'
Error executing cl.exe.
The source code:
#include <iostream.h>
#if defined(_M_IX86)
typedef unsigned __int8 u8_t;
#endif
class test{
template <class T>
int getSize(T const &val)
{
return sizeof(val);
}
};
template <class T>
int getSize(T const &val)
{
return sizeof(val);
}
int main()
{
test tt;
int t=tt.getSize< u8_t >(0); //error here
int tmp=getSize< u8_t >(0);
cout << tmp << " : " << sizeof( __int8 ) << endl;
return 0;
}
I had a problem by using microsoft visual C++ 6.0 to compiling a simple code. using template function in a class seems not work.
Everything works fine by using g++ compiler.
Does anyone have some solution for this problem?
Thanks in advance.
Liwen
The error message as following
Compiling...
testit.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\tmp\testit.cpp(26) : error C2275: 'u8_t' : illegal use of this type as an expression
C:\Program Files\Microsoft Visual Studio\MyProjects\tmp\testit.cpp(4) : see declaration of 'u8_t'
Error executing cl.exe.
The source code:
#include <iostream.h>
#if defined(_M_IX86)
typedef unsigned __int8 u8_t;
#endif
class test{
template <class T>
int getSize(T const &val)
{
return sizeof(val);
}
};
template <class T>
int getSize(T const &val)
{
return sizeof(val);
}
int main()
{
test tt;
int t=tt.getSize< u8_t >(0); //error here
int tmp=getSize< u8_t >(0);
cout << tmp << " : " << sizeof( __int8 ) << endl;
return 0;
}