Nested Template Class failed

N

Nephi Immortal

Why doesn’t my code work?

Error 3 error C2511: 'void Outer<Outer_Type>::_Type<Type1>::test(void)' : overloaded member function not found in 'Outer<Outer_Type>::_Type<Type1>' d:\main.cpp

enum Types
{
Type1,
Type2
};

template< Types Outer_Type >
struct Outer
{
template< Types Type >
struct _Type;

template<>
struct _Type< Type1 >
{
void test();
};

_Type< Type1 > Do();
};

void Outer< Type1 >::_Type< Type1 >::test()
{
}

Outer< Type1 >::_Type< Type1 > Outer< Type1 >::Do()
{
return _Type< Type1 >();
}

int main()
{
Outer< Type1 > x;
x.Do().test();

return 0;
}
 
Z

Zhihao Yuan

template<>
struct _Type< Type1 >
{
void test();
};

I don't quite catch what you want to do here, but an explicit
specialization in a class scope is not allowed. However, a partial
specialization is OK.

template< Types Type, typename Enable = void>
struct _Type;

template <typename Enable>
struct _Type<Type1, Enable> {
void test();
};
void Outer< Type1 >::_Type< Type1 >::test()
{
}

Syntax error. Should be:

template <> template <>
void Outer< Type1 >::_Type< Type1 >::test()
{
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top