Skip to main content
GameDev.net gamedev.net
🔒 Locked

STL vector and const method problem

Started by Iftah Jan 18, 2007 at 7:49 AM 1 replies 750+ views
Original Post
Iftah
Iftah
hi I have this A class containing vector of pointers to B class and Show method (const) being sent down, problem is I get error: invalid conversion from 'B* const* const' to 'B**' my code goes like this:

class B
{
public:
   void foo();
   void show() const;
};

class A
{
public:
   void show() const;
   void do_foo_stuff();

private:
   vector vect;
};

void A::show() const
{
   B * b;
   vector iter = vect.begin();

   cout<< "here are the B objects: ";
   for (; iter != vect.end(); ++iter)
   {
       b = *iter;
       b->show();
   }
}


thanks in advance
Skizz
Skizz
You need to use a const_iterator it step through the vector.

However, "show" implies a state change so it shouldn't really be const. Having it const will mean at some point along the line a mutable or const_cast is probably going to be required (i.e. to do "m_visible = true").

Skizz
Iftah
Iftah
thanks, const_iterator is what I needed

show is marked const, in my case "show" is just dumping private data to screen and doesnt change object state.

thanks!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.