0

What happens when a normal object wants to call a constant member function??

25th Dec 2016, 8:09 AM
Jotheeswaran M
Jotheeswaran M - avatar
3 ответов
+ 3
Like what @Vladislav stated, it depends. If the normal object calls a constant member just to modify it, it will throw an error. Otherwise, it will work like a normal function.
25th Dec 2016, 8:21 AM
Wen Qin
Wen Qin - avatar
+ 1
Constant member functions guarantees that fields of object won't be modified. If object is marked as const, calling the non-constant function will throw an error. So if const function doesn't modify - the code works, if it does - compiler throws an error.
25th Dec 2016, 8:20 AM
Vladislav
Vladislav - avatar
0
A normal object calls a constant member function with no error! :)
25th Dec 2016, 8:19 AM
Jotheeswaran M
Jotheeswaran M - avatar