undefined reference to `

This is a discussion on undefined reference to ` within the C Programming forums, part of the General Programming Boards category; Hi, I was wondering why the following classes' destructors are not executed? Code: class A{ int *i; public: A(){ i=new ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    159

    destructors not executed

    Hi,
    I was wondering why the following classes' destructors are not executed?
    Code:
    class A{
        int *i;
    public:
    A(){    i=new int[2];    };
    ~A(){    delete[] i;    };
    };
    
    class B: public A{
        int *j;
    public:
    B(){    j=new int[2];};
    ~B(){    delete [] j;};
    };
    
    int main()
    {
        A* a = new B();
         return 0;
    }
    Thank you!
    Last edited by lehe; 03-26-2009 at 06:41 PM.

  2. #2
    Registered User
    Join Date
    Jan 2009
    Posts
    159
    Ok, I know the answer. I forgot to delete a.
    Sorry for spamming here.
    Is it possible to delete one's own posts in this forum?

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    this is C++ and should be on another forum
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,029
    You shouldn't delete your own posts (unless perhaps you double post in error), because others can see your benefit and profit from the wisdom you gained by solving the problem.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 12:45 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 05:42 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21