Ask your own question, for FREE!
Computer Science 4 Online
OpenStudy (aravindg):

can we overload a destructor? If so , how?

OpenStudy (aravindg):

@Opcode

OpenStudy (opcode):

You can't overload a destructor, because there is only one destructor per class in C++.

OpenStudy (aravindg):

but we could overload constructors isnt it?

OpenStudy (opcode):

I have question thou... Why would you need to overload a destructor o.O? Could we overload constructors? Simple answer is yes.

OpenStudy (aravindg):

lols it was a question in model question papers

OpenStudy (aravindg):

ya i saw that during constrctor overloading they used a constructor like code(){ } what is its use?

OpenStudy (konradzuse):

that's a default constructor..

OpenStudy (opcode):

I'm confused on the question. Are you trying to ask whats a constructors overloading?

OpenStudy (aravindg):

no i knw that

OpenStudy (opcode):

Oh, okay.

OpenStudy (aravindg):

but i dont understand the use of default constructor

OpenStudy (aravindg):

i read the compiler provides a constructor by its own if we dont use that and all..got confused

OpenStudy (konradzuse):

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.

OpenStudy (konradzuse):

Sometimes you don't need to pre-define anything.....

OpenStudy (opcode):

Well a default constructor is like: example() : member1(), member2(), member3(), ... {}

OpenStudy (konradzuse):

a constructor is called once to do things for the class. For example call methods.

OpenStudy (aravindg):

but my question why should we declare it if we dont initialise anything inside it?

OpenStudy (konradzuse):

something is always inside it. I don't think I've ran across anything without something in it...

OpenStudy (opcode):

I'm trying to find something better to explain this than me >.>

OpenStudy (aravindg):

ok

OpenStudy (konradzuse):

Where have you encountered what you're asking?

OpenStudy (aravindg):

in a program using constructor overloading

OpenStudy (konradzuse):

A constructor is meant to construct, if there is nothing to construct, then there is no point in

OpenStudy (konradzuse):

sometimes you don't even need them, but that's unwise.

OpenStudy (aravindg):

later in the program they initialised like code D; D=A; where A was a defined constructor

OpenStudy (konradzuse):

when you overload constructors you're just making multiple ones.

OpenStudy (konradzuse):

you might weant to post the entire example please.

OpenStudy (konradzuse):

brb

OpenStudy (aravindg):

thats a big program ...and i will have to leav for exam soon

OpenStudy (opcode):

@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.

OpenStudy (aravindg):

the part of code is given above

OpenStudy (aravindg):

ok leav dat then...what is the use of new statement in constructors?

OpenStudy (opcode):

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.

OpenStudy (aravindg):

example?

OpenStudy (opcode):

New statement: http://stackoverflow.com/questions/7847525/explanation-of-this-new-statement New statement allow you to fix memory leaks and such.

OpenStudy (aravindg):

reading........

OpenStudy (aravindg):

lols that one is advanced level new

OpenStudy (aravindg):

i need basic use of new operator

OpenStudy (opcode):

You should try this site: http://www.cplusplus.com Here is the exact one: http://www.cplusplus.com/reference/new/operator%20new/

OpenStudy (aravindg):

ok

OpenStudy (aravindg):

how can we copy contents of one file to another?

OpenStudy (konradzuse):

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();

OpenStudy (aravindg):

nvm ..its time for me to leav for exam thanks fora ll the help :)

OpenStudy (konradzuse):

Yup, np, anymore q's please let me know...

OpenStudy (anonymous):

http://stackoverflow.com/questions/988925/how-to-overload-a-destructor is pretty good

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!