J
Joost Ronkes Agerbeek
Should I remove const from a private member just for the sake of the
assignment operator?
I have a class that looks something like this.
class Foo
{
public:
Foo(const std::string& description) : _description(description) {}
private:
const std::string _description;
};
The compiler warns me that it cannot generate an assignment operator,
because _description is const. _description will never change unless you
assign a new object to the Foo-instance. Does that warrant making
_description non-const.
Somehow I see oldFoo = newFoo more as assigning a new object to the
oldFoo-identifier than as changing the oldFoo-object. Is that a poor grasp
of concept on my side?
Thanks in advance.
assignment operator?
I have a class that looks something like this.
class Foo
{
public:
Foo(const std::string& description) : _description(description) {}
private:
const std::string _description;
};
The compiler warns me that it cannot generate an assignment operator,
because _description is const. _description will never change unless you
assign a new object to the Foo-instance. Does that warrant making
_description non-const.
Somehow I see oldFoo = newFoo more as assigning a new object to the
oldFoo-identifier than as changing the oldFoo-object. Is that a poor grasp
of concept on my side?
Thanks in advance.