Jump to content
  • Advertisement
Sign in to follow this  
Jonbca

Array help

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

Im working on a project for my computer science class and i keep getting an error on every array i use. the error i get is: 'Board::Get_Width' : cannot convert 'this' pointer from 'const Board' to Board &'. This occurs every time i try to call a method from one of the objects in the array. If anyone could give me a hand, that would be great. Here is a snippet of the code.
class BoardPile{
private:
  Board stack[50];

public:
...

void Print() const {
  cout << "Length (inches)\t\tDimensions" << endl;	
  cout << "---------------\t\t----------" << endl;
  for(int i = 0; i< 50; i++){				
    if(stack.Get_Length() > 0)
      cout << stack.Get_Length() << "\t\t\t" << stack.Get_Width() << "x" << stack.Get_Height() << endl;
    }
  }
}

Share this post


Link to post
Share on other sites
Advertisement
Get_Width() probably isn't defined as a const method.

Since Print() is defined as const, it's only allowed to call other const methods in the object. Once you start tagging methods as const, you pretty much have to follow through with it everywhere.

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!