As the other answers said, obj is a reference to a const base object. However, this does not mean that the object to which it refers is either of type base , or the object to which it refers is equal to const , just func cannot change obj through that . For instance:
struct derived : base { ... }; derived d; func(d);
is legal, and:
bool other_func(const base& b, other_object& o) { base b_copy = b; o.foo(); return b_copy == b; }
can return false if o has an internal non-constant reference to b (or something inside it) and o.foo() modifies b . This has practical implications for features such as
std::string::operator=(const std::string& other);
where a naive implementation might do the wrong thing for my_str = my_str .
source share