Is it possible to call this member int MyClass::get(int key) const
instead of the int& MyClass::get(int key)
? In other words, where in the C++ source codes, a value can be used but not a reference?
#include <iostream>
using namespace std;
class MyClass {
public:
MyClass(int input) : i(input) {};
int i;
int get(int key) const {
std::cout << "int get(int key) const " << key << std::endl;
return i;
}
int& get(int key) {
std::cout << "int& get(int key) " << key << std::endl;
return i;
}
};
void dummy(const int helpme)
{
std::cout << helpme << std::endl;
}
int main() {
// your code goes here
MyClass abc(6);
std::cout << abc.get(13) << std::endl;
int result = (int)abc.get(16);
dummy(abc.get(18));
return 0;
}