operator overloading - Regarding const qualifier in C++ -
operator overloading - Regarding const qualifier in C++ -
i not able understand error why not accepting const qualifier
[error] passing 'const abc' 'this' argument of 'int abc::getarea()' discards qualifiers [-fpermissive] here code below.
#include<iostream> using namespace std; class abc{ public: abc(){ } abc(int a,int b){ length=a; height=b; } int getarea(){ homecoming length*height; } bool operator <(const abc&) const; private: int length; int height; }; bool abc::operator <(const abc& d) const{ homecoming getarea() < d.getarea(); } int main(){ abc a(10,12); abc b(13,15); if(a < b) cout << "\n b has larger volume"; else cout << "\n has larger volume"; homecoming 0; }
int abc::getarea() not marked const beingness called on const object 1 of const fellow member functions. should mark getarea fellow member function const because not alter state of object.
c++ operator-overloading const
Comments
Post a Comment