Solved

Which constructor is being called?

Posted on 2013-06-14
4
474 Views
Last Modified: 2013-06-14
Two constructors are as follows:

UsbSocket::UsbSocket(unsigned short tId)
: _callTask(tId),
  ...
{
  ...
  ...
}


UsbSocket::UsbSocket(unsigned short rxBuffsize, unsigned short txBuffsize, unsigned short tId)
: _callTask(tId),
  ...
{
 ...
 ....
}


A class is getting instantiated as follows:

UsbSocket *_usb;

_usb = new UsbSocket();


I believe above Two constructors are not getting called.  Is the default constructor getting called?

We work on embedded ARM7 based target.  We used Keil Tools.
If the default constructor is getting called, what does it do?  Do I need to look at the compiler manual to find out what the default constructor does in my system?
0
Comment
Question by:naseeam
  • 2
  • 2
4 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 500 total points
ID: 39248312
>>I believe above Two constructors are not getting called.  Is the default constructor getting
>>called?

Yes, indeed - only the default constructor matches the argument list (i.e. no arguments at all). Only if the 1st ctor would have a default argulent like 'UsbSocket::UsbSocket(unsigned short tId = 0)', it would match. Since that is not the case, the default constructor is used.
0
 
LVL 1

Author Comment

by:naseeam
ID: 39248325
What does the default constructor do?  There are so many members in this class.  I need to know what are they getting initialized to.
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 39248364
If there is no default constructor in the code, a compiler-generated one will be invoked. This one only does a minimum amount of initialization (will depend on the compiler). The best would be if you would provide your own default constructor,
0
 
LVL 1

Author Closing Comment

by:naseeam
ID: 39248679
Thanks for explaining  the constructor confusion.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question