1
void f(){}
void f(int x){}
void f(float x){}
void f(int x,bool y){}
2
void f(const int& x){}
void f(int&& x){}
int main()
{
const int x = 0;
int y = 0;
f(x);
f(y);
f(0);
f(std::move(x));
}
3
#include <iostream>
struct Cls {
int x;
int& get()
{
std::cout << "get" << std::endl;
return x;
}
const int& get() const
{
std::cout << "const get" << std::endl;
return x;
}
};
int main()
{
Cls c{0};
c.get();
const Cls s{1};
s.get();
return 0;
}
4
#include <iostream>
struct Cls {
int res = 0;
const int& get() const&
{
std::cout << "const get&" << std::endl;
return res;
}
int& get()& {
std::cout <<"get&"<< std::endl;
return res;
}
int&& get()&& {
std::cout <<"get&&"<<std::endl;
return std::move(res);
}
};
int main()
{
Cls c;
c.get();
auto& a = c;
a.get();
const auto& b = c;
b.get();
std::move(c).get();
return 0;
}