Connecting Tech Pros Worldwide Help | Site Map

to allocate memory dynamically to a class

stonny
Guest
 
Posts: n/a
#1: Sep 4 '06
Hi, I saw a program like the following:


*******************************************
class Image
{
public:
...
Private:
...
};

Image * imagePtr;
imagePtr = new Image();
....
delete imagePtr;
*********************************************

Why the sentence is: image = new Image()?

I thought it should be : image = new Image{}.

Thanks

Stonny
peter koch
Guest
 
Posts: n/a
#2: Sep 4 '06

re: to allocate memory dynamically to a class



stonny wrote:
Quote:
Hi, I saw a program like the following:
>
>
*******************************************
class Image
{
public:
...
Private:
...
};
>
Image * imagePtr;
imagePtr = new Image();
...
delete imagePtr;
*********************************************
>
Why the sentence is: image = new Image()?
Because the standard says so.
Quote:
>
I thought it should be : image = new Image{}.
Ok. Youre wrong then - what made you think so?

/Peter

xmli1976@gmail.com
Guest
 
Posts: n/a
#3: Sep 4 '06

re: to allocate memory dynamically to a class


image = new Image;should be ok.
stonny 写道:
Quote:
Hi, I saw a program like the following:
>
>
*******************************************
class Image
{
public:
...
Private:
...
};
>
Image * imagePtr;
imagePtr = new Image();
...
delete imagePtr;
*********************************************
>
Why the sentence is: image = new Image()?
>
I thought it should be : image = new Image{}.

Thanks

Stonny
Closed Thread