J
JT
I have a compiler error when using a non-dependent type declared in a
template, if I use the type in function definitions. I think it is a
parsing issues related to confusion with a typename. Below I have a
simple example. Is there another solution I should be using instead of
declaring the type outside of the template?
Thanks,
JT
For a class, this works, and the typedef is available in the function
definition...
class Test
{
typedef int myIntTypedef;
myIntTypedef funct();
};
Test::myIntTypedef Test::funct()
{
return 0;
}
For a template, however, the above does not work, because (I think) the
type is not available. The compiler (VC++7.1) suggests I use typename
for the type, which is not correct in this case.
template <class T>
class Test2
{
typedef int myIntTypedef;
myIntTypedef funct();
};
template <class T>
Test2<T>::myIntTypedef Test2<T>::funct() // error "dependent name is
not a type"
{
return 0;
}
If I define the type outside of the template, it will work...
typedef int myIntTypedef;
template <class T>
class Test3
{
myIntTypedef funct();
};
template <class T>
Test3<T>::myIntTypedef Test3<T>::funct()
{
return 0;
}
template, if I use the type in function definitions. I think it is a
parsing issues related to confusion with a typename. Below I have a
simple example. Is there another solution I should be using instead of
declaring the type outside of the template?
Thanks,
JT
For a class, this works, and the typedef is available in the function
definition...
class Test
{
typedef int myIntTypedef;
myIntTypedef funct();
};
Test::myIntTypedef Test::funct()
{
return 0;
}
For a template, however, the above does not work, because (I think) the
type is not available. The compiler (VC++7.1) suggests I use typename
for the type, which is not correct in this case.
template <class T>
class Test2
{
typedef int myIntTypedef;
myIntTypedef funct();
};
template <class T>
Test2<T>::myIntTypedef Test2<T>::funct() // error "dependent name is
not a type"
{
return 0;
}
If I define the type outside of the template, it will work...
typedef int myIntTypedef;
template <class T>
class Test3
{
myIntTypedef funct();
};
template <class T>
Test3<T>::myIntTypedef Test3<T>::funct()
{
return 0;
}