By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,655 Members | 959 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,655 IT Pros & Developers. It's quick & easy.

Second argument to operator=

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
"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

P: n/a
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

P: n/a


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

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.