By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,987 Members | 1,552 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,987 IT Pros & Developers. It's quick & easy.

faq new as parameter in the constructor

P: n/a
Hi,

CarPtr g()
{
CarPtr p(new Car()); <-- How to explain this
// ...
return p;
}
Thanks.
Apr 20 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
fcvcnet wrote:
Hi,

CarPtr g()
{
CarPtr p(new Car()); <-- How to explain this
CarPtr is a class. The above statement constructs a CarPtr object named
p with a parameter that is a raw pointer to a dynamically allocated Car
object.
// ...
return p;
}
Thanks.

Apr 20 '06 #2

P: n/a
fcvcnet wrote:
Hi,

CarPtr g()
{
CarPtr p(new Car()); <-- How to explain this
// ...
return p;
}


What's there to explain? It's called "initialisation". You may
have seen it before. You can even do that with built-in types,
like a double:

double pi(3.1415926);

V
--
Please remove capital As from my address when replying by mail
Apr 20 '06 #3

P: n/a
Thanks.
Apr 20 '06 #4

P: n/a
benben wrote:
fcvcnet wrote:
Hi,

CarPtr g()
{
CarPtr p(new Car()); <-- How to explain this
CarPtr is a class.


It is? How do you now that?
The above statement constructs a CarPtr object named p with a parameter
that is a raw pointer to a dynamically allocated Car object.


Yes. However, CarPtr could also be a typedef for Car*.
// ...
return p;
}
Thanks.


Apr 20 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.