Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > BOOK: Professional C++, 2nd Edition
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional C++, 2nd Edition
This is the forum to discuss the Wrox book Professional C++, 2nd Edition by Marc Gregoire, Nicholas A. Solter, Scott J. Kleper ; ISBN: 978-1-1181-6995-7
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional C++, 2nd Edition section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 7th, 2012, 02:22 AM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Constructors, pg. 39 vs 42

I am new to C++ and didn't recognize the syntax used in the Employee constructor on page 39, but I shrugged and just assumed that was the weird way C++ did things. Then I got to page 42 and saw the type of syntax I'm more used to (e.g., from Java) for the Database class. Why is one syntax used on page 39 and another used on page 42?

[Edit: It occurs to me I might get a reply quicker if I don't make people run from their books, so the code snippet from page 39 is:
Code:
Employee::Employee()
    : mFirstName("")
    , mLastName("")
    , mEmployeeNumber(-1)
    , mSalary(kDefaultStartingSalary)
    , bHired(false)
  {
  }
And the code snippet from page 42 is:
Code:
Database::Database()
  {
    mNextEmployeeNumber = kFirstEmployeeNumber;
  }

Last edited by janetmweiss; December 7th, 2012 at 03:20 AM. Reason: Added code
  #2 (permalink)  
Old December 8th, 2012, 06:09 AM
Wrox Author
Points: 220, Level: 4
Points: 220, Level: 4 Points: 220, Level: 4 Points: 220, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2011
Posts: 49
Thanks: 0
Thanked 4 Times in 4 Posts
Default

C++ supports both; you can either use the syntax from page 39 which uses an initialization list to initialize members in a constructor, or you can use the syntax from page 42. More details on the syntax is given in chapter 6 in the section on constructors.
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
pg 81 why is there 2 constructors with paramaters flipped? mikezx10 BOOK: Professional ASP.NET Design Patterns 4 February 25th, 2012 04:49 AM
Page 39 - insertAfter MattCruikshank BOOK Programming Interviews Exposed: Secrets to Landing Your Next Job 2nd Ed ISBN: 978-0-470-12167-2 1 May 27th, 2011 02:06 PM
Chapter 2, pg 39 Bodman@live.ca BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 2 April 21st, 2009 01:42 AM
Undefined session variables Ch.2 pg. 38-39 outtaMyBlood BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 2 March 14th, 2009 02:19 PM



All times are GMT -4. The time now is 12:38 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.