Jump to content
  • Advertisement
Sign in to follow this  
Amnesty2

Need to make this lazy

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

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]

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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;
};

Share this post


Link to post
Share on other sites
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;
};

Share this post


Link to post
Share on other sites
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. :/

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!