I have code in the constructor in my class. Yet when I want the game Im doing restart I would like to reset the class.
in C# it would be CMyClass class;
class = new CMyClass();
What is the way to do this in c++
I have code in the constructor in my class. Yet when I want the game Im doing restart I would like to reset the class.
in C# it would be CMyClass class;
class = new CMyClass();
What is the way to do this in c++
1) Make a function which reinitializes all of the variables in your class.
2) Destroy the instance of the class and make a new one. (Assuming you've allocated it dynamically.)
Quzah.
Hope is the first step on the road to disappointment.
Try creating a copy constructor and/or assignment operator, and then doing:
Probably not the most efficient, since it involves constructing a new object and then copying it into obj. More efficient would be, as quzah said, just make a function that reinitializes everything outside of the constructor.Code:MyClass obj(whatever arguments you pass to constructor); obj = MyClass(whatever arguments you pass to constructor the second time around);
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Or you could have a member function reset() in your CMyClass which resets the class as you want.
I guess you didn't read the 1) in my reply.Originally Posted by anykey
Quzah.
Hope is the first step on the road to disappointment.
Oh yes, I missed that.I guess you didn't read the 1) in my reply.
Great minds think alike, huh?