Second argument to operator=

E

exits funnel

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::eek:perator= (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
 
V

Victor Bazarov

exits funnel said:
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:


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

foo::eek:perator= (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
 
?

=?iso-8859-1?Q?Juli=E1n?= Albo

exits funnel escribió:
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.
 
E

exits funnel

Victor said:
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
 
V

Victor Bazarov

exits funnel said:
[...]
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,148
Messages
2,570,838
Members
47,385
Latest member
Joneswilliam01

Latest Threads

Top