help please with simple one!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have a simple program which works when I compile with my g++
from command line like:  g++ test.cpp --- no problems.


but If I do g++ -m32 test.cpp  it crashes right at the delete [] temp
statement. If I change the temp pointer type to Child all is well.
what am I doing wrong. If you guys just say I am just dumb that's
good.but I need to know what's wrong.  my g++ version is listed beflow
for your reference. please CC to my email address as I am not on any
kind of mailing list related gnu gcc. Thanks for all your help.

see the code below.

#include <iostream>

static int mcount = 0;
using namespace std;
class Base
{
  public:
    Base( int i, int j) { };
    virtual ~Base() {cout <<"delete"<<endl; };
    virtual void hui() { cout <<"hello world"<<endl; };
  private:
    int temp12;
};

class Child : public Base
{
  public:
    Child(int i, int j) : Base(i,j) {};
    virtual ~Child() {};
    virtual void hui() { cout <<"world hello world"<<endl; };
  private:
    int temp23;
};

int main(int argc, char **argv)
{
  Base *temp = new Child [1024] (3, 2);
  temp[0].hui();

  delete [] temp;
}

-- 

Regards
Raghu

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux