can we overload a destructor? If so , how?
@Opcode
You can't overload a destructor, because there is only one destructor per class in C++.
but we could overload constructors isnt it?
I have question thou... Why would you need to overload a destructor o.O? Could we overload constructors? Simple answer is yes.
lols it was a question in model question papers
ya i saw that during constrctor overloading they used a constructor like code(){ } what is its use?
that's a default constructor..
I'm confused on the question. Are you trying to ask whats a constructors overloading?
no i knw that
Oh, okay.
but i dont understand the use of default constructor
i read the compiler provides a constructor by its own if we dont use that and all..got confused
I just had to look up what "constructor" overloading is... It's just creating multiple constructors. A default constructor is used in most cases where you're just creating an instance of a class. For example lets say you want a class called Time(). You can have public Time() { this.minutes = 30; this.hours = 2; } Or you could do public Time(int min, int hour) { this.minutes = min; this.hours = hour; } which you can then personally say what your mins or hours are.
Sometimes you don't need to pre-define anything.....
Well a default constructor is like: example() : member1(), member2(), member3(), ... {}
a constructor is called once to do things for the class. For example call methods.
but my question why should we declare it if we dont initialise anything inside it?
something is always inside it. I don't think I've ran across anything without something in it...
I'm trying to find something better to explain this than me >.>
ok
Where have you encountered what you're asking?
in a program using constructor overloading
A constructor is meant to construct, if there is nothing to construct, then there is no point in
sometimes you don't even need them, but that's unwise.
later in the program they initialised like code D; D=A; where A was a defined constructor
when you overload constructors you're just making multiple ones.
you might weant to post the entire example please.
brb
thats a big program ...and i will have to leav for exam soon
@AravindG Konrad is correct, I've looked at many examples... There always seems to be something in it... No matter what or where the example is.
the part of code is given above
ok leav dat then...what is the use of new statement in constructors?
I found it! This should explain what you need: http://www.parashift.com/c++-faq/ctors.html New statement to provide values for data members and avoid separate assignment statements.
example?
New statement: http://stackoverflow.com/questions/7847525/explanation-of-this-new-statement New statement allow you to fix memory leaks and such.
reading........
lols that one is advanced level new
i need basic use of new operator
You should try this site: http://www.cplusplus.com Here is the exact one: http://www.cplusplus.com/reference/new/operator%20new/
ok
how can we copy contents of one file to another?
What exactly are you trying to do? You can do thingsi believe like Rectangle r = new Rectangle(); then later on say r = new Rectangle(5, 5,5,5); (x,y,w,h); I know you can say Rectangle r; which just makes an instance of it, and then set it as an object later doing r = new Rectangle();
nvm ..its time for me to leav for exam thanks fora ll the help :)
Yup, np, anymore q's please let me know...
http://stackoverflow.com/questions/988925/how-to-overload-a-destructor is pretty good
Join our real-time social learning platform and learn together with your friends!