class - () operator overloading c++ -


i have confusion calling of overloaded operator().

there 2 functions in class matrix:

float operator()(int, int) const; // suppose call function rvalue float& operator()(int, int); // , lvalue 

now when call them in main, in way :

matrix m2(3, 2); m2(0, 0) = 1; // here lvalue should called int c=m2(0,0); // , here rvalue 

but in both cases calls lvalue function. why??

if comment lvalue function , do

int c=m2(0,0); // calls rvalue function 

but in presence of both functions, calls lvalue function. why?

hope, question clear.

rvalues of class types not const might think. const overload called on const qualified objects, otherwise least qualified version preffered.

what can overload ref-qualifiers (c++11 only):

float operator()(int, int) && const; // called when object rvalue  float& operator()(int, int) &;       // called when object lvalue 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -