Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Which constructor is being called?

Posted on 2013-06-14
4
Medium Priority
?
487 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 2000 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

824 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