Sign in to follow this  

C++ template specialisation and compiler errors

This topic is 3595 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I'm trying to specialise template implementations with respect to inheritence information, viz:
#include <iostream>
using namespace std;

class A {
public:
	class X {};
};

class B : public A {
public:
	class X {};
};

template <typename T>
void foo () {
	cout << "plain\n";
}

template <>
void foo<A::X> () {
	cout << "Type A\n";
}

template <>
void foo<B::X> () {
	cout << "Type B\n";
}

template <typename T>
void bar (T t) {
	foo<T::X> (); // Line 31
}

int main () {
	A a;
	B b;
	bar(a); // Line 37
	bar(b); // Line 38
	return 0;
}
The output of gcc is this:
Quote:
test.cpp: In function 'void bar(T) [with T = A]': test.cpp:37: instantiated from here test.cpp:31: error: dependent-name 'T::X' is parsed as a non-type, but instantiation yields a type test.cpp:31: note: say 'typename T::X' if a type is meant test.cpp: In function 'void bar(T) [with T = B]': test.cpp:38: instantiated from here test.cpp:31: error: dependent-name 'T::X' is parsed as a non-type, but instantiation yields a type test.cpp:31: note: say 'typename T::X' if a type is meant
WTF does this mean? Thanks for looking.

Share this post


Link to post
Share on other sites

This topic is 3595 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this