473,396 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

faq new as parameter in the constructor

Hi,

CarPtr g()
{
CarPtr p(new Car()); <-- How to explain this
// ...
return p;
}
Thanks.
Apr 20 '06 #1
4 1390
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
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
Thanks.
Apr 20 '06 #4
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mysooru | last post by:
Hi All, One of the ATL class..... template <class Base> class CComObject : public Base { public: typedef Base _BaseClass;
5
by: selder21 | last post by:
Hello, I have a class with constructor taking a const string&. Now i want to call this constructor with a string literal. Because this is of type char* there are overload resolution conflicts....
16
by: Steven T. Hatton | last post by:
As far as I know, there is no way to provide a default value for the argument to the constructor A::A(char (&array)) in this example. Correct? struct A{ A(char (&array) ){...
8
by: Tony Johansson | last post by:
Hello Experts! What does this mean actually. If you have a template with a type and non-type template argument, say, like this template<typename T, int a> class Array {. . .}; then A<int,...
2
by: Tony Johansson | last post by:
Hello! I use method forName and newInstance in class Class like this instance = (GameFactory)(Class.forName(name).newInstance() ); Now to my question: Assume that name is GameFactory then I...
2
by: Doug | last post by:
I have probably a simple question: How do I declare a class to have a parameter of a certain type? I want to declare frmAppointment to pass a parameter of DateTime so when I call it, I call do...
4
by: Anthony Coelho | last post by:
Hello Guru's! I am trying to pass a function pointer as a parameter to a method and can't seem to get it working. Basically I want to do the exact same thing that the System.Threading.Thread...
19
by: George | last post by:
Hi all. How can I check and return an error on a constructor that receives a pointer as a parameter and the parameter is null. Is there any possibility to return an error? or do I have to create...
3
by: Fei Liu | last post by:
Hello, We all know that a template function can automatically deduce its parameter type and instantiate, e.g. template <tpyename T> void func(T a); func(0.f); This will cause func<floatto...
9
by: tadmill | last post by:
Is it possible to pass a generic parameter of the same class to to its constructor, where the "T" type passed in the constructor is different than the "T" type of the instanced class? ie, ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.