Jump to content
  • Advertisement
Sign in to follow this  

STL: passing containers to template functions (error)

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

I've been having some problems with STL and just when I thought I was getting the hang of things, I get stuck again :( What I want to do is pass a vector to a template function and iterate through it. (I know about std::for_each and use it often, but this is for a different purpose.) This is my code:
template <typename container>
void print(container& c)
  typedef typename container::iterator Iter;
  for ( Iter it = c.begin(); it != c.end(); ++it)
std::vector<Obj*> vecObj;
print( vecObj );

I get the error: left of '->val' must point to class/struct/union see reference to function template instantiation 'void __cdecl print(const class std::vector<class Obj *,class std::allocator<class Obj *> > &)' being compiled What up? Someone said MSVC6 has problems with template specializations and I do remember seeing a 'Failed to specialize...' for one of the (many) bits of code I tried. Thanks in advance.

Share this post

Link to post
Share on other sites
"I get the error: left of '->val' must point to class/struct/union"
If you look at the order of precedence you will see '*' is lower than '->', therefore you are deferencing the iterator and accessing it and then deferencing the structure value . To force the order you want try

typos fixed.

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!