Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Constructors and Destructors Practice | Constructors and Destructors
C++ OOP

book
Constructors and Destructors Practice

Task
test

Swipe to show code editor

  • Finish the implementation of the ResourceHolder class constructors.
    • Create and implement a default constructor.
    • Create and implement a constructor with parameters.
    • Create and implement a copy constructor.
    • Create and implement a destructor.

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 9
#include <iostream>

class ResourceHolder {
public:
int* p_data;
};

int main()
{
ResourceHolder obj1(100);
ResourceHolder obj2(obj1);
ResourceHolder obj3;
*obj1.p_data = -100;
std::cout << *obj1.p_data << ' ' << *obj2.p_data << ' ' << obj3.p_data;
}
toggle bottom row
We use cookies to make your experience better!
some-alt