Solved

Which constructor is being called?

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

Technology Partners: 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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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.

630 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