Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ overloading by ref-qualifiers

#include <stdio.h>

class My {
public:
    int get(int) & { // notice &
        printf("returning int..
");
        return 42;
    }
    char get(int) && { // notice &&
        printf("returning char..
");
        return 'x';
    };
};

int main() {
    My oh_my;
    oh_my.get(13); // 'oh_my' is an lvalue
    My().get(13); // 'My()' is a temporary, i.e. an rvalue
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #overloading
ADD COMMENT
Topic
Name
6+6 =