# Array help

## 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 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 on other sites
Thanks a lot, that worked perfectly.

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627665
• Total Posts
2978523

• 10
• 10
• 12
• 22
• 13