This is what I am trying to accomplish:
struct test{};
const test returnconst(){
return test();
}
test returnnonconst(){
return test();
}
int main(){
test t1=returnnonconst();
const test t2=returnnonconst();
test t3=returnconst();
const test t4=returnconst();
}
The compiler accepts all four calls to return *. I understand that in the third call, a copy of the object is created, but instead I want to force the caller to returnconstsave the value as const. Is there any way around this?
source
share