I am trying the following in MSV2010
namespace statismo {
template<>
struct RepresenterTraits<itk::Image<itk::Vector<float, 3u>, 3u> > {
typedef itk::Image<itk::Vector<float, 3u>, 3u> VectorImageType;
typedef VectorImageType::Pointer DatasetPointerType;
typedef VectorImageType::Pointer DatasetConstPointerType;
typedef typename VectorImageType::PointType PointType;
typedef typename VectorImageType::PixelType ValueType;
};
I am getting the following error:
error C2899: typename cannot be used outside a template declaration
An help in a workaround would be greatly appreciated.
namespace statismo {
template<>
struct RepresenterTraits<itk::Image<itk::Vector<float, 3u>, 3u> > {
// bla
typedef typename VectorImageType::PointType PointType;
^^^^^^^^
typedef typename VectorImageType::PixelType ValueType;
^^^^^^^^
};
Your typename
keywords are placed inside the explicit specalization of RepresenterTraits<T>
for itk::Image<itk::Vector<float, 3u>, 3u>
. However, this is a regular class, not a class template. This means that VectorImageType
is not a dependent name and the compiler knows that PixelType
is a nested type. That's why it's not allowed to use typename
. See als this Q&A.
Note that in C++11, this restriction has been lifted, and the use of typename
is allowed but not required in non-template contexts. See e.g. this example
#include <iostream>
template<class T>
struct V
{
typedef T type;
};
template<class T>
struct S
{
// typename required in C++98/C++11
typedef typename V<T>::type type;
};
template<>
struct S<int>
{
// typename not allowed in C++98, allowed in C++11
// accepted by g++/Clang in C++98 mode as well (not by MSVC2010)
typedef typename V<int>::type type;
};
struct R
{
// typename not allowed in C++98, allowed in C++11
// accepted by g++ in C++98 mode as well (not by Clang/MSVC2010)
typedef typename V<int>::type type;
};
int main()
{
}
Live Example (Just play with the g++/clang and std=c++98 / std=c++11 command line options).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With