Need to make this lazy

Started by
3 comments, last by Moonshoe 15 years, 9 months ago

template<class Container>
class F
{
public:
	typedef typename Container::iterator iterator;
};


template <class Type, std::size_t Size>
class my_container : private F<my_container<Type,Size> > 
{
public:
	typedef Type* iterator;
};



My compiler complains my_container doesnt define iterator. The compiler is trying to fully define F first, and iterator inside my_container isn't defined yet. Is their any trick to get this to compile? VC++ 2005 btw [Edited by - Amnesty2 on July 16, 2008 12:39:27 AM]
Advertisement
Ok, I'm taking the risk to look stupid (who cares anyway)

Why not just:

template <class Type, std::size_t Size>class my_container{public:	typedef Type* iterator;};


By no means do I consider myself a template guru (I hate templates :P)
Strange...I compiled this on VC++ 2005 and Dev-C++ and they both compile fine.

Maybe try this...

template <class Type, std::size_t Size>class my_container : private F{public:	typedef Type* iterator;};
Quote:Original post by Moonshoe
Strange...I compiled this on VC++ 2005 and Dev-C++ and they both compile fine.
Make sure you actually instantiate the template.
E.g. my_container<int,42> test;


You could add the iterator type as another argument of the F template:
template<class T, class I>class F{public:	typedef I iterator;};template <class Type, std::size_t Size>class my_container : private F<my_container<Type,Size>,Type*> {	typedef F<my_container<Type,Size>,Type*> F;public:	using F::iterator;};
Quote:Original post by Hodgman
Quote:Original post by Moonshoe
Strange...I compiled this on VC++ 2005 and Dev-C++ and they both compile fine.
Make sure you actually instantiate the template.
E.g. my_container<int,42> test;


Oh yeah, thanks.

I'm seeing the errors now. :/

This topic is closed to new replies.

Advertisement