Hello,
I have following piece of code:
It compiles without problems under gcc-3.4, gcc-4.3, intel compiler, but fails under MSVC9.
MSVC tells "use of undefined type c_traits<C>
, while compiling class template member function void foo<C>::go(void)
with C=short.
The point it the compiler tries to install unused member function of unused class, because this class is just not used at all.
I can work-around the issue by specializing entire class foo instead of specializing its member function. But the point it that specializing entire class is little bit problematic for me for different reasons.
The big question: what is right?
- Is my code wrong and gcc and intel compiler just ignore the issue because they do not install foo fully, or
- The code is correct and this is bug of MSVC9 (VC 2008) that it tries to install unused member functions?
The code:
class base_foo {
public:
virtual void go() {};
virtual ~base_foo() {}
};
template<typename C>
struct c_traits;
template<>
struct c_traits<int> {
typedef unsigned int_type;
};
template<typename C>
class foo : public base_foo {
public:
static base_foo *create()
{
return new foo<C>();
}
virtual void go()
{
typedef typename c_traits<C>::int_type int_type;
int_type i;
i=1;
}
};
template<>
base_foo *foo<short>::create()
{
return new base_foo();
}
int main()
{
base_foo *a;
a=foo<short>::create(); delete a;
a=foo<int>::create(); delete a;
}