This is what I'm 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(); //I want this to be a compile error
const test t4=returnconst();
}
The compiler accepts all of the four return* calls. I understand that in the third call a copy of the object is constructed, but I want instead to force the caller of returnconst
to store the value as const
. Are there workaround to this?