Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 7th, 2012, 03:22 AM
Registered User
 
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 04:20 AM.. Reason: Added code
 
Old December 8th, 2012, 07:09 AM
Wrox Author
 
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.





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 05: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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.