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

April 12th, 2014, 06:15 PM
|
|
Registered User
|
|
Join Date: Apr 2014
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

April 13th, 2014, 04:31 AM
|
|
Wrox Author
|
|
Join Date: Mar 2011
Posts: 49
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
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
|
|

April 13th, 2014, 01:15 PM
|
|
Registered User
|
|
Join Date: Apr 2014
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Marc Gregoire
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
|
|

May 7th, 2014, 10:39 PM
|
|
Registered User
|
|
Join Date: Apr 2014
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

May 8th, 2014, 08:25 PM
|
|
Friend of Wrox
|
|
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts
|
|
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
|
|

May 9th, 2014, 10:26 AM
|
|
Wrox Author
|
|
Join Date: Mar 2011
Posts: 49
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
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.
|
|
 |