Passing object by refer to a function??

I doing an assignment where i have to create a pig bank class that stores the number of pennies nickels dimes and quarters. I need to create a function to handles the printing of the class. I'm suppose to pass the object by reference and use const where appropriate. The pass by reference i have figured out. But when i had const to the function i get errors. Here's what i have and the error.

1
2
3
4
5
6
void printCBankObject(const CBank &); //function prototype

printCBankObject(object1); // function call

void printCBankObject(const CBank& theObject) // function deff
         cout << right << setw(20) << "pennies: " << theObject.getPennies() << endl; // on of five lines that print the different data members of my class 


This is the error:

error: Semantic Issue: Member function 'getNickels' not viable: 'this' argument has type 'const CBank', but function is not marked const


I thought the const on the arguments part of a function just made is so that when you passed by reference it made what ever your passing not accessible to being changed.
I thought the const on the arguments part of a function just made is so that when you passed by reference it made what ever your passing not accessible to being changed.

Yeah, but you're trying to call a member function that can change the object (i.e. it is not marked const).
Topic archived. No new replies allowed.