Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder adarshakb's Avatar
    Join Date
    Jun 2009
    Location
    Silicon valley of india
    Posts
    247
    Thanks
    11
    Thanked 1 Time in 1 Post

    class and objects

    1......................
    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..........................
    and can we call a destructor forcefullly without delete
    Last edited by adarshakb; 07-15-2009 at 01:53 PM. Reason: spell error

  • #2
    Regular Coder adarshakb's Avatar
    Join Date
    Jun 2009
    Location
    Silicon valley of india
    Posts
    247
    Thanks
    11
    Thanked 1 Time in 1 Post
    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

  • #3
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Quote Originally Posted by adarshakb View Post
    1......................
    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..........................
    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.
    OracleGuy

  • #4
    Regular Coder adarshakb's Avatar
    Join Date
    Jun 2009
    Location
    Silicon valley of india
    Posts
    247
    Thanks
    11
    Thanked 1 Time in 1 Post
    hmm.. i know its a decade old.. and i prefet .net 2003 edition

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

    and how to call the destructor.. still not answered

    thks for the reply

  • #5
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Quote Originally Posted by adarshakb View Post
    and how to call the destructor.. still not answered
    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.
    Last edited by oracleguy; 07-15-2009 at 05:22 PM.
    OracleGuy

  • #6
    Regular Coder BrickInTheWall's Avatar
    Join Date
    Mar 2009
    Location
    Munich, Germany
    Posts
    139
    Thanks
    1
    Thanked 13 Times in 13 Posts
    You can call the destructor like any other member function, but like oracleguy said, this can result in memory leaks.

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •