Wrox Programmer Forums
|
BOOK: Ivor Horton's Beginning Visual C++ 2012
This is the forum to discuss the Wrox book Ivor Horton's Beginning Visual C++ 2012 by Ivor Horton; ISBN: 978-1-118-36808-4
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Visual C++ 2012 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 July 6th, 2013, 03:57 AM
Registered User
 
Join Date: Jul 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default a question in chapter 8

On page 356,

(motto1 = motto2) = motto3;

If the return type is just CMessage, this will not be legal because a temporary copy of the original object is actually returned so it will be an rvalue, and the compiler will not allow a member function call using an rvalue.

However, on page 361,

// Function to add two CBox objects
CBox CBox::operator+(const CBox& aBox) const
{
// New object has larger length and width, and sum of heights
return CBox(m_Length > aBox.m_Length ? m_Length : aBox.m_Length,
m_Width > aBox.m_Width ? m_Width : aBox.m_Width,
m_Height + aBox.m_Height);
}

the function above is legal for the similar operation like,

smallBox + mediumBox + certainBox


The question is,

the explicit overloaded function call for the assignment operation is

(motto1.operator=(motto2)).operator=(motto3);


the explicit overloaded function call for the addition operator is

(smallBox.operator+(mediumBox)).operator+(certainB ox);


Is there any distinction between the two explicit overloaded function, considering they both return a temporary copy if the former's return type is CMessage? I can't see much difference between them. But the former is not legal and the latter is legal.

Thank you!
 
Old July 6th, 2013, 05:06 AM
Registered User
 
Join Date: Jul 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Maybe it's wrong with “the compiler will not allow a member function call using an rvalue” because the following code is legal:

(motto1=motto2).showit(); //supposing the return type of operator=() function is CMessage

The real reason for the above question is the second assignment is done on the temporary copy if the return type is CMessage.

Is that right?
 
Old May 25th, 2014, 10:17 AM
Registered User
 
Join Date: May 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm working on it.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about chapter 6 Candino2 BOOK: Excel VBA 24-Hour Trainer 1 February 26th, 2013 02:30 PM
Chapter 1 Question JohnNWFS BOOK: Beginning Android 4 Application Development 2 June 24th, 2012 10:38 AM
A better example of Chapter 5 Question 6 dspearing BOOK: Beginning Microsoft Visual C# 2008 ISBN: 978-0-470-19135-4 1 April 6th, 2010 08:16 PM
Chapter 4 question davidle1234 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 January 18th, 2007 12:18 AM





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