Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualnoatom

Posted 08 April 2013 - 02:43 AM

The code:

 

class ra{
public:

};


ra hey(){
ra io;
return io;
}

void e(ra& i){
	std::cout << "on" << std::endl;
}
int main() {
	e(hey());
}

 

 

Why does that compile? shouldn't the call to ra in main,return a temporary object,which is a const,an rvalue? So e shouldn't accept it,because it's a const!

 

Why does the above code work?


#3noatom

Posted 07 April 2013 - 08:45 AM

The code:

 

class ra{
public:

};


ra hey(){
ra io;
return io;
}

void e(ra& i){
	std::cout << "on" << std::endl;
}
int main() {
	e(hey());
}

 

 

Why does that compile? shouldn't the call to ra in main,return a temporary object,which is a const,an rvalue? So e shouldn't accept it,because it's a const!

 

Why does the above code work?


#2noatom

Posted 04 April 2013 - 08:32 AM

The code:

 

class ra{
public:

};


ra hey(){
ra io;
return io;
}

void e(ra& i){
	std::cout << "on" << std::endl;
}
int main() {
	e(hey());
}

 

 

Why does that compile? shouldn't the call to ra in main,return a temporary object,which is a const,an rvalue? So e shouldn't accept it,because it's a const!

 

Why does the above code work?


#1noatom

Posted 04 April 2013 - 07:43 AM

The code:

 

class ra{
public:

};


ra hey(){
ra io;
return io;
}

void e(ra& i){
	std::cout << "on" << std::endl;
}
int main() {
	e(ra());
}

 

 

Why does that compile? shouldn't the call to ra in main,return a temporary object,which is a const,an rvalue? So e shouldn't accept it,because it's a const!

 

Why does the above code work?


PARTNERS