Can someone tell why i'm getting this error when compling this class?
class C
{
public:
void func(const C &obj)
{
//body
}
private:
int x;
};
void func2(const C &obj)
{
obj.func(obj);
}
int main() { /*no code here yet*/}
The C::func() method doesn't promise that it won't modify the object, it only promises that it won't modify its argument. Fix:
void func(const C &obj) const
{
// don't change any this members or the compiler complains
}
Or make it a static function. Which sure sounds like it should be when it takes a C object as an argument.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With