Jump to content
  • Advertisement
Sign in to follow this  
Sfpiano

Inherited template typedefs

This topic is 3856 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

// helper.h
namespace Helper {
	template <class T>
	struct allocHelper {
		typedef T&       reference;
	};
}
//
#include "helper.h"
template <class T>
class Tree : public Helper::allocHelper<T> {
public:
	typedef typename Helper::allocHelper<T>::reference reference;

	void fn(reference r) {
		r = r;
	}
}

template <class T>
class SelfBalancedTree : public Tree<T> {
public:
	void fn2(reference rr) {
		rr = rr;
	}
}
fn() compiles fine, but I'm getting the following error in fn2(): error: `reference' has not been declared error: ISO C++ forbids declaration of `rr' with no type

Share this post


Link to post
Share on other sites
Advertisement
I'm no template whizz, but try this:

template <class T>
class SelfBalancedTree : public Tree<T> {
public:
void fn2(typename Tree<T>::reference rr) {
rr = rr;
}
}

Share this post


Link to post
Share on other sites
It's because reference does not exist in SelfBalancedTree<T>, it exits in Tree<T>, so you have to qualify its namespace fully.
It might be sensible to re-typedef it in the subclass.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!