...

View Full Version : class and objects



adarshakb
07-15-2009, 02:51 PM
1......................:confused:
If i have a class emp

to declare a new object;

emp x;//allowed
emp x(9);//allowed

but whynot
emp x();

i know tat the above call refers to a function and emp x; refers to a memory type emp and location name x......
but doesnt emp x(9); also refer to a function... why is this a prob if we refer to t a no-arg construc like emp x()???

2..........................:p
and can we call a destructor forcefullly without delete

adarshakb
07-15-2009, 02:59 PM
and how to view destructor function output in VC++ 6.0..
in turbo i can go back to the screen but in VC++ how can i see destrutor output when out of main function:D

oracleguy
07-15-2009, 05:24 PM
1......................:confused:
If i have a class emp

to declare a new object;

emp x;//allowed
emp x(9);//allowed

but whynot
emp x();

i know tat the above call refers to a function and emp x; refers to a memory type emp and location name x......
but doesnt emp x(9); also refer to a function... why is this a prob if we refer to t a no-arg construc like emp x()???


Because that isn't the syntax, in C++ a no argument constructor doesn't use any parenthesis.



2..........................:p
and can we call a destructor forcefullly without delete

You could but it is a horribly bad thing to do. Don't do it. Besides, if you dynamically allocate the memory, just calling the destructor without a delete does not deallocate the memory and your program will leak memory.

As for using VC6, that is about a decade old, do yourself a favor and upgrade into the 21st century.

adarshakb
07-15-2009, 05:55 PM
hmm.. i know its a decade old.. and i prefet .net 2003 edition:thumbsup:

but my col doesnt have tat and use VC6 cos it serves their purpose and they dont care to upgrade :eek:... systems having new softwares are always busy any way:p

and how to call the destructor.. still not answered :D

thks for the reply

oracleguy
07-15-2009, 06:19 PM
and how to call the destructor.. still not answered :D


You don't want to, it is really bad design. What are you trying to do that you think you need to call the destructor yourself? There is probably a better way to do it.

BrickInTheWall
07-16-2009, 05:53 PM
You can call the destructor like any other member function, but like oracleguy said, this can result in memory leaks.

a.~Destr(); //pa->~Destr();



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum