Solved

Which constructor is being called?

Posted on 2013-06-14
4
397 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
 

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
 

Author Closing Comment

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now