I have a function in a class with const
key word:
bool Machiavelli::IsStraight(std::vector<Card>& cards) const{}
Machiavelli is class that have other classes inside, like Card and Table:
class Table{
private:
std::map<int, std::vector<Card> > table;
....
};
The vector
in the function is a vector of table
. The function check if the cards assemble a straight.
Now, in the function I change the value of a data of Card function:
cards[i].SetIntValue(14);
where SetIntValue
is a function in Card class.
Reading some question, I read:
const
after a function declaration means that the function is not allowed to change any class members (except ones that are marked mutable).
The function doesn't know that the argument is in Machiavelli, so I can change a class member: table
. Where my reasoning fails?