Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- class Test
- {
- std::string value;
- public:
- Test(const Test & test): // copy c-tor
- value(test.value)
- {
- std::cout << "Test::Test(Test)";
- }
- Test(std::string value): //c-tor from value
- value(value)
- {
- std::cout << "Test::Test(string)";
- }
- };
- Test genTest() // to create temporary
- {
- Test test = Test("string");
- return test;
- }
- class Container
- {
- Test test;
- public:
- Container():
- test(genTest()) // initialize from temporary
- {
- }
- };
- int main()
- {
- Container container;
- return 0;
- }
- //Output:
- //Test::Test(string)
- //Copy constructor is unused
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement