Constructor and Destructor for static member variable (a pointer)
I am working on a class ex1 which needs one static member variable y. That static member variable is a pointer to an object of class ex2 which has its own constructor and destructor. Now I know how to initialize the variable y by defining it outside the class. But how to call the destructor for variable y? I need to use delete statement, but where to place that statement. I need to call both constructor and destructor of class ex2. An equivalent code of my problem is shown below with the output: #include<iostream> class ex2 { public: int n; ex2(int num) { n = num; std::cout << "Constructor of
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.