Re: simple question.
raghuv119@gmail.com wrote:
:: forgot to mention, The breakage is at the line where
::
:: Base *temp = new child[16385] (3, 2);
::
:: and then delete [] temp;- <--- crash
::
:: if temp is a child pointer everything is ok.
You have answered it yourself! :-)
The type of the pointer passed to delete[] must be the same as the one
returned from new[].
C style arrays are not polymorphic, and can't be used this way.
::
:: On Aug 10, 4:34 pm, "raghuv...@gmail.com" <raghuv...@gmail.com>
:: wrote:
::: what am I doing wrong here. on a 64 bit m/c if I just do g++
::: t.cpp everything works find. if I do g++ -m32 t.cpp it just
::: breaks. ====================
::: #include <iostream>
:::
::: static int mcount = 0;
::: using namespace std;
::: class Base
::: {
::: public:
::: Base( int i, int j) { cout <<i<<"\t"<<j<<endl; };
::: virtual ~Base() { };
::: virtual void hui() { cout <<"hello world"<<endl; };
::: protected:
::: int temp12;
:::
::: };
:::
::: class Child : public Base
::: {
::: public:
::: Child(int i, int j) : Base(i,j) {};
::: ~Child() {};
::: virtual void hui() { cout <<"world hello world"<<endl; };
::: protected:
::: int temp23;
:::
::: };
:::
::: int main(int argc, char **argv)
::: {
::: Base *temp = new Child [16384] (3, 2);
::: temp[0].hui();
This isn't really working either. Don't try temp[1].hui() !!
:::
::: delete [] temp;
:::
::: }
Bo Persson