Sign in to follow this  

Array help

This topic is 4758 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[i].Get_Length() > 0)
      cout << stack[i].Get_Length() << "\t\t\t" << stack[i].Get_Width() << "x" << stack[i].Get_Height() << endl;
    }
  }
}

Share this post


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

This topic is 4758 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this