Sign in to follow this  
samgzman

initializing member pointer to template class' member struct?

Recommended Posts

I have a template class, with a memeber struct and a static-member-pointer to this struct. I am having a nightmare of a time trying to initialize this staic pointer to null due to the templateness of the outer class. Its easy to get working when the struct is defined outside of the template class, but i don't want it to be exposed... If this is not possible, then the language seems to be incoherent since it allows templates, it allows nested classes/structs, as well as static members and pointers, but it doesnt allow a template class to init a pointer to a member struct? I would be much obliged if anyone solves this little riddle.
	template <class T>
	class A
	{
	private:

		struct B {..};

		static B* Bptr;
	};

	// I have tried the following:
	template <class T> A<T>::B*  A<T>::Bptr = 0;  // NO NO NO

	template <class T> A<T>::B* template <class T> A<T>::Bptr = 0; // Not happenin either.... :(

Share this post


Link to post
Share on other sites
Looks like you're missing a typename keyword. Try:

template <class T>
typename A<T>::B * A<T>::Bptr = 0;

Share this post


Link to post
Share on other sites

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