0

Solve the following code. Please give me justification that why program is giving the error

#include<iostream> using namespace std; class Demo { int value; public: Demo(int v = 0) {value = v;} void showMessage() { cout<<"showMessage() Function"<<endl; } void display()const { cout<<"display() Function"<<endl; } }; int main() { const Demo d1; d1.showMessage(); d1.display(); return(0); }

26th Apr 2020, 5:53 PM
Areej
1 Answer
+ 2
You cannot call non-const function with const object. However, You can call const function, with non-const object.
26th Apr 2020, 6:02 PM
Mustafa K.
Mustafa K. - avatar