Solved

Which constructor is being called?

Posted on 2013-06-14
4
476 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

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…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

730 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