Question about constructors...

Well, i have a question about constructors. I know that the default constructor and the destructor are needed always... but how do i know if copy and conversion constructors are needed?

I have done some exercises where it said i need to make default, copy and conversion constructors and a destructor, but when i checked the solution, only the default consturctor, destructor and a constructor with all the priavte variable declared was used... no use of copy or conversion constructor...

Can anyone explain me all this a bit? Because i got a bit confused...

I know that the default constructor and the destructor are needed always..
Nope. Deafault, copy constructor and destructor are compiler generated if you didn't define them. So does assignment operator.
Rule of three: if you need to define one of following: destructor, copy constructor or assignment operator, you probably should define others too.
Last edited on
SO basically if i let them out, nothing is wrong if i get this right?
-and the purpose in that exercise was to just know how to write them and what they do i suppose?
closed account (3qX21hU5)
If you have a pointer in your class you will generally need to define your own copy constructor, assignment operator, and destructor.'

Some classes with pointers can get by with implicit copy control but usually you will want to define your own.

There are some other special cases where you will need to define copy control but usually you should be fine with the compiler generated ones.
Topic archived. No new replies allowed.