Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4. a) Why is the destructor called 3 times? b) On which row will the Token object be created, which will disappear first? c) Why

4. a) Why is the destructor called 3 times? b) On which row will the Token object be created, which will disappear first? c) Why does this object disappear before the other two objects? d) Why is the default constructor called only once?

1 #include 2 #include 34 class Token { 5 public: 6 Token() { std::cout << "Token()"; } 7 ~Token() { std::cout << "~Token()"; } 8 }; 9 10 template 11 std::unique_ptr foo(T t0) { 12 return std::unique_ptr(new T(t0)); 13 }; 14 15 int main() { 16 Token&& t = Token(); 17 18 auto ptr = foo(t); 19 20 return 0; 21 }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

Who did you wish to speak to?

Answered: 1 week ago