473,396 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Interview question.

Name two cases where you MUST use initialization list as opposed to
assignment in constructors.

Aug 13 '07 #1
7 1254
?? wrote:
Name two cases where you MUST use initialization list as opposed to
assignment in constructors.
Think of what cannot be constructed without initialisation. What do
you initialise in the initialisation list? Base classes and members,
right? So, what would require a class to be placed in the initialiser
list? What would require a member to be placed there?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 13 '07 #2
刘昊 wrote:
Name two cases where you MUST use initialization list as opposed to
assignment in constructors.
Only 2 ?
Aug 13 '07 #3
Gianni Mariani wrote:
?? wrote:
>Name two cases where you MUST use initialization list as opposed to
assignment in constructors.

Only 2 ?
Only 2 that the interviewER could think of, I take it.
Aug 13 '07 #4
"??" <le**********@gmail.comwrote in message
news:11**********************@i13g2000prf.googlegr oups.com...
Name two cases where you MUST use initialization list as opposed to
assignment in constructors.
References and Base Classes are two.
Aug 13 '07 #5
On Aug 13, 11:37 am, "Jim Langston" <tazmas...@rocketmail.comwrote:
"??" <leomayleo...@gmail.comwrote in message

news:11**********************@i13g2000prf.googlegr oups.com...
Name two cases where you MUST use initialization list as opposed to
assignment in constructors.

References and Base Classes are two.
Also, I believe constant members must also be initialized in the
intialization
list.

Aug 13 '07 #6
Alf P. Steinbach wrote:
2. Member variables with user-defined constructors.
Actually, just those missing a default constructor.
Aug 14 '07 #7
Alf P. Steinbach wrote:
* Jim Langston:
>"??" <le**********@gmail.comwrote in message
news:11**********************@i13g2000prf.googleg roups.com...
>>Name two cases where you MUST use initialization list as opposed to
assignment in constructors.

References and Base Classes are two.

Language level technical reasons:

1. Base classes.
2. Member variables with user-defined constructors.
3. Member variables with inaccessible or inappropriate assignment operator.
4. "const" member variables.
5. Reference members.

Other technical reasons:

6. When there are dependencies between member variables so that
some must be initialized before one where 1...5 applies.

Non-technical reasons:

7. When the coding guideline or other authority says so.
Number 8 is a "meta" reason for meta programming.

8. When initializing an member of a template class that you cannot
determine what type it will be because not doing so will result in
potential problems either with uninitialized POD's.

i.e.

template <typename Tstruct X
{
T v;
X() : v() {}
};

X<inti; // i.v is initialized to zero
X<std::strings; // s.v is initialized to ""

I suppose it's not really a MUST ...
Aug 14 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

54
by: Spammay Blockay | last post by:
I've been tasked with doing technical interviews at my company, and I have generally ask a range of OO, Java, and "good programming technique" concepts. However, one of my favorite exercises I...
10
by: Gopal Krish | last post by:
I was asked this question in an interview. How can you display the contents of an ASP page (from another web server) in a aspx page, ie, first half of the screen will display contents from asp...
0
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
0
by: connectrajesh | last post by:
INTERVIEWINFO.NET http://www.interviewinfo.net FREE WEB SITE AND SERVICE FOR JOB SEEKERS /FRESH GRADUATES NO ADVERTISEMENT
18
by: Nobody | last post by:
I've been looking for a job for a while now, and have run into this interview question twice now... and have stupidly kind of blown it twice... (although I've gotten better)... time to finally...
2
by: freepdfforjobs | last post by:
Full eBook with 4000 C#, JAVA,.NET and SQL Server Interview questions http://www.questpond.com/SampleInterviewQuestionBook.zip Download the JAVA , .NET and SQL Server interview sheet and rate...
0
by: freesoftwarepdfs | last post by:
Ultimate list of Interview question website.....Do not miss it http://www.questpond.com http://msdotnetsupport.blogspot.com/2007/01/net-interview-questions-by-dutt-part-2.html...
0
by: Free PDF | last post by:
..NET , SQL Server interview questions websites.... http://www.questpond.com http://www.geocities.com/dotnetinterviews/...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.