Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > BOOK: Professional C++, 2nd Edition
|
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 April 12th, 2014, 06:15 PM
Registered User
 
Join Date: Apr 2014
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation calling a method from another object class

Hello, can anyone helpe with the following:
rr.getNext().doWorkDuringTimeSlice(); I´ve copied this code from professional C++ second edition which raised: how can a method from class Process to be called from a object from class RoundRobin? page 411.
I´ll be gratefull for the answer. Tanks a lot, Robson
 
Old April 13th, 2014, 04:31 AM
Wrox Author
 
Join Date: Mar 2011
Posts: 49
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Hi,

rr is of type RoundRobin<Process>.
Calling getNext() on rr returns a reference to a Process on which you can then call doWorkDuringTimeSlice().

Marc
 
Old April 13th, 2014, 01:15 PM
Registered User
 
Join Date: Apr 2014
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Marc Gregoire View Post
Hi,

rr is of type RoundRobin<Process>.
Calling getNext() on rr returns a reference to a Process on which you can then call doWorkDuringTimeSlice().

Marc
MARC, Thank you so much, Robson
 
Old May 7th, 2014, 10:39 PM
Registered User
 
Join Date: Apr 2014
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Is really necessary a reference return to addEmployee ?

Hello. This is about page 42 and 46. Your first useful program.

I don´t believe the method addEmployee needs to return a reference.
I set this function to return void and I also commented out the return code
in that method. I tested all cases in the user interface at runtime though the
program worked properly.

Am I right?

code
void Database::addEmployee(string inFirstName, string inLastName)
{
Employee theEmployee;
theEmployee.setFirstName(inFirstName);
theEmployee.setLastName(inLastName);
theEmployee.setEmployeeNumber(mNextEmployeeNumber+ +);
theEmployee.hire();
mEmployees.push_back(theEmployee);

// return mEmployees[mEmployees.size()-1];
}
/code

page 46

code
void doHire(Database& inDB)
{
string firstName;
string lastName;

cout << "First name? ";
cin >> firstName;
cout << "Last name? ";
cin >> lastName;

try {
inDB.addEmployee(firstName, lastName);
} catch (const std::exception&) {
cerr << "Unable to add new employee!" << endl;
}
}
/code
 
Old May 8th, 2014, 08:25 PM
Friend of Wrox
 
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts
Default

It is not required that a method like add return a reference to the object that it has added but if it does you can continue to do operation on the reference after adding it


I.e.

DB.AddEmployee("bill", "bob").Age = 23;

Her I have added an employee and set his age all in one line of code
 
Old May 9th, 2014, 10:26 AM
Wrox Author
 
Join Date: Mar 2011
Posts: 49
Thanks: 0
Thanked 4 Times in 4 Posts
Default

mmorgan30 is correct.
It's not required to return a reference, but client code could use it to immediately call another method on the new employee.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Page 210:Page object calling a private method from BasePage? aperture8 BOOK: Beginning ASP.NET 4 : in C# and VB 6 August 9th, 2010 07:04 AM
calling a parent class method from a child class (Zend Cert) crmpicco Beginning PHP 2 July 30th, 2010 04:22 AM
Calling a btn_click method dhirajDac ASP.NET 2.0 Professional 2 April 18th, 2008 07:52 AM
Doubt in clone Method of Object Class pandian Java Basics 1 October 12th, 2006 03:29 PM
calling private method from another class jack_3 C# 3 December 16th, 2005 07:56 PM





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