This file contains hidden or 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 NonCopyable { | |
| public: | |
| NonCopyable(const NonCopyable&) = delete; | |
| NonCopyable& operator=(const NonCopyable&) = delete; | |
| private: | |
| ... | |
| } |
This file contains hidden or 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 DoublePrinter { | |
| public: | |
| void print(double aDouble) { | |
| std::cout << "Value is: " << aDouble << std::endl; | |
| } | |
| }; | |
| DoublePrinter dp; |
This file contains hidden or 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 DoublePrinter { | |
| public: | |
| void print(double aDouble) { | |
| std::cout << "Value is: " << aDouble << std::endl; | |
| } | |
| void print(float) = delete; | |
| }; |
This file contains hidden or 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 CrashDestination { | |
| public: | |
| CrashDestination(const std::string& aString) | |
| : theString(aString) | |
| {} | |
| void print() const { std::cout << theString << std::endl; } | |
| private: | |
| const std::string& theString; | |
| }; |
This file contains hidden or 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 CrashDestination { | |
| public: | |
| CrashDestination(const std::string& aString) | |
| : theString(aString) | |
| {} | |
| CrashDestination(const std::string&&) = delete; | |
| void print() const { std::cout << theString << std::endl; } | |
| private: | |
| const std::string& theString; |
This file contains hidden or 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 hidden or 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 hidden or 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; | |
| }; |
This file contains hidden or 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 hidden or 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); | |
| } |
OlderNewer