This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class T { | |
... | |
foo() const; // Here *this is const | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class T { | |
... | |
foo() const; // *this is const | |
bar() &; // *this is an l-value | |
goo() &&; // *this is an r-value | |
... | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class JumboFactory { | |
... | |
Jumbo getJumboByCopy() { | |
return theJumboObject; | |
} | |
... | |
private: | |
Jumbo theJumboObject; | |
}; | |
JumboFactory myJF; | |
Jumbo myJumbo = myJF.getJumboByCopy(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Jumbo myJumbo = JumboFactory().getJumboByCopy(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class JumboFactory { | |
... | |
Jumbo getJumboByCopy() const & { | |
//Deep copy | |
return theJumboObject; | |
} | |
Jumbo getJumboByCopy() && { // *this is an r-value | |
//Move | |
return std::move(theJumboObject); | |
} | |
... | |
private: | |
Jumbo theJumboObject; | |
}; | |
JumboFactory myJF; | |
Jumbo myJumboA = myJF.getJumboByCopy(); // Deep copy | |
Jumbo myJumboB = JumboFactory().getJumboByCopy(); // Move |