Skip to main content
gamedev.net
🔒 Locked

Array help

Started by Jonbca 1 reply 950+ views
Original Post
Jonbca
Jonbca
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;
    }
  }
}

Morbo
Morbo
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.
Jonbca
Jonbca
Thanks a lot, that worked perfectly.

Topic Locked

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

Sign in to reply to this topic.