473,395 Members | 2,151 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Second argument to operator=

Hello,

I'm working my way through 'Thinking in C++' by Bruce Eckel. One of the
exercises and the end of chapter 12 is the following:
Create a class with an assignment operator that has a second argument,
a string that has a default value that says "op-call." Create a function
that assigns an object of your class to another one and show that your
assignment operator is called correctly.


When I try to compile the code I've written for this exercise my
compiler complains:

foo::operator= (const foo &, basic_string<char,string_char_traits<char>,
__default_alloc_template<true, 0> >) must take exactly one argument.

This seems to contradict the intent of the excercise. I've poked around
the net (including the FAQ for this group) to find clarification on the
issue but havn't found any. So what gives? Is my compiler wrong or is
Exckel's exercise broken? Thanks in advance.

-exits

Jul 22 '05 #1
4 1642
"exits funnel" <ex*********@NOSPAMyahoo.com> wrote...
I'm working my way through 'Thinking in C++' by Bruce Eckel. One of the
exercises and the end of chapter 12 is the following:
Create a class with an assignment operator that has a second argument,
a string that has a default value that says "op-call." Create a function that assigns an object of your class to another one and show that your
assignment operator is called correctly.


When I try to compile the code I've written for this exercise my
compiler complains:

foo::operator= (const foo &, basic_string<char,string_char_traits<char>,
__default_alloc_template<true, 0> >) must take exactly one argument.

This seems to contradict the intent of the excercise. I've poked around
the net (including the FAQ for this group) to find clarification on the
issue but havn't found any. So what gives? Is my compiler wrong or is
Exckel's exercise broken? Thanks in advance.


Eckel's exercise is broken. The Standard requires that a user-declared
copy assignment operator has only one parameter. See 12.8/9 and 13.5.3.

Victor
Jul 22 '05 #2
exits funnel escribió:
Create a class with an assignment operator that has a second argument,
a string that has a default value that says "op-call." Create a function
that assigns an object of your class to another one and show that your
assignment operator is called correctly.

When I try to compile the code I've written for this exercise my
compiler complains:


I suppose that here "second argument" means the argument in the right
side of the =, not that the function operator = takes two arguments.

Regards.
Jul 22 '05 #3


Victor Bazarov wrote:
"exits funnel" <ex*********@NOSPAMyahoo.com> wrote...
I'm working my way through 'Thinking in C++' by Bruce Eckel. One of the
exercises and the end of chapter 12 is the following:

Create a class with an assignment operator that has a second argument,
a string that has a default value that says "op-call." Create a

function
that assigns an object of your class to another one and show that your
assignment operator is called correctly.


When I try to compile the code I've written for this exercise my
compiler complains:

foo::operator= (const foo &, basic_string<char,string_char_traits<char>,
__default_alloc_template<true, 0> >) must take exactly one argument.

This seems to contradict the intent of the excercise. I've poked around
the net (including the FAQ for this group) to find clarification on the
issue but havn't found any. So what gives? Is my compiler wrong or is
Exckel's exercise broken? Thanks in advance.

Eckel's exercise is broken. The Standard requires that a user-declared
copy assignment operator has only one parameter. See 12.8/9 and 13.5.3.

Victor


Victor, thanks for the clarification. I had a feeling that that was the
case. One question though: what are '12.8/9' and '13.5.3' references
to? The chapter numbers seem to make sense with respect to the FAQ but
there's no 8 or 9 in chapter 12 of the only version I can find online
which is :
http://www.parashift.com/c++-faq-lite/

-exits

Jul 22 '05 #4
"exits funnel" <ex*********@NOSPAMyahoo.com> wrote...
[...]
Victor, thanks for the clarification. I had a feeling that that was the
case. One question though: what are '12.8/9' and '13.5.3' references
to?


To the Standard.

Victor
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: Steven Bethard | last post by:
So I end up writing code like this a fair bit: map = {} for key, value in sequence: map.setdefault(key, ).append(value) This code basically constructs a one-to-many mapping -- each value that...
3
by: jimjim | last post by:
Hello, My question concerns as to how a pointer is passed by reference as a function argument. The following is from code taken from the MICO implementation of the CORBA specification. in...
8
by: Hunter Hou | last post by:
hello, I'm reading <the C++ programming language>, here's a question for bind2nd. Who can help explain what on earth bind2nd is working? .... void rotate_all( list<Shape*>& ls, int angle ) {...
3
by: BigMan | last post by:
Here is a piece of code: #include <memory> using namespace std; template< typename SomeType > void f(auto_ptr_ref< SomeType >) { }
4
by: cayblood | last post by:
Hello, I have the following class declaration in an include file: class Node { public: Node(string name = ""); Node(const Node& node); Node& operator=(const Node& node); bool...
1
by: mente_fredda | last post by:
Hi I'm in trouble with operator new: I have overloaded it to track allocated memory, but what I really need is to get constructor argument. /////////////CODE: class myClass { public:...
17
by: Klaas Vantournhout | last post by:
Hi all, I was wondering if it is possible if you can check in a function if one of the arguments is temporary. What I mean is the following. A is a class, foo is a function returning a class...
30
by: Angel Tsankov | last post by:
Hello! Does the C++ standard define what happens when the size argument of void* operator new(size_t size) cannot represent the total number of bytes to be allocated? For example: struct S {...
15
by: puzzlecracker | last post by:
I see that a lot of former in the code, and wonder if there is a technical reason for that
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.