Topic: does operator= inherited by derive class ?
Author: "Sebastian Moleski" <sebmol@gmx.net>
Date: 2000/05/19 Raw View
The OP has sent me a reply to my message that goes as follows:
<<I know that it is hidden - but is it inherited ?
I mean is the code below is legal ?
Struct B
{
void operator=(int){}
};
Struct D: public B
{
using B::operator=;
};
void main()
{
D d;
d = 3; // is this legal ?
}>>
The respective part of the standard on this issue (12.8 Copying class
objects [class.copy], paragraph 10):
"A using-declaration that brings in from a base class an assignment
operator with a parameter type that could be that of a copy-assignment
operator for the derived class is not considered an explicit
declaration of a copy-assignment operator and does not supporess the
implicit declaration of the the derived class copy-assignment
operator; the operator introduced by the using-declaration is hidden
by the implicitly-declared copy-assignment operator in the derived
class."
The code above is always legal because an operator= is implicitly
declared when none suitable is present.
--
Sebastian Moleski
----
The Borland C++ Builder bug lists:
http://www.crosswinds.net/~bcbbugs/
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Gil Shafriri" <gilsh@microsoft.com>
Date: 2000/05/19 Raw View
Mybe the code is valid - that what I'm trying to find out , but I don't
undersatand the argument :
"The code above is always legal because an operator= is implicitly
declared when none suitable is present."
So the compiler implicitly define copy assignment operator.
Why that makes assigning integer to the class legal ?
"Sebastian Moleski" <sebmol@gmx.net> wrote in message
news:8fttd3$1j8m$1@news.nikoma.de...
> The OP has sent me a reply to my message that goes as follows:
> <<I know that it is hidden - but is it inherited ?
> I mean is the code below is legal ?
>
> Struct B
> {
> void operator=(int){}
> };
>
> Struct D: public B
> {
> using B::operator=;
>
> };
>
> void main()
> {
> D d;
> d = 3; // is this legal ?
>
> }>>
>
> The respective part of the standard on this issue (12.8 Copying class
> objects [class.copy], paragraph 10):
> "A using-declaration that brings in from a base class an assignment
> operator with a parameter type that could be that of a copy-assignment
> operator for the derived class is not considered an explicit
> declaration of a copy-assignment operator and does not supporess the
> implicit declaration of the the derived class copy-assignment
> operator; the operator introduced by the using-declaration is hidden
> by the implicitly-declared copy-assignment operator in the derived
> class."
>
> The code above is always legal because an operator= is implicitly
> declared when none suitable is present.
>
> --
> Sebastian Moleski
> ----
> The Borland C++ Builder bug lists:
> http://www.crosswinds.net/~bcbbugs/
>
>
> ---
> [ comp.std.c++ is moderated. To submit articles, try just posting with ]
> [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
> [ --- Please see the FAQ before posting. --- ]
> [ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
>
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Sebastian Moleski" <sebmol@gmx.net>
Date: 2000/05/19 Raw View
Gil Shafriri <gilsh@microsoft.com>:
| Mybe the code is valid - that what I'm trying to find out , but I
don't
| undersatand the argument :
|
| "The code above is always legal because an operator= is implicitly
| declared when none suitable is present."
|
| So the compiler implicitly define copy assignment operator.
| Why that makes assigning integer to the class legal ?
Sorry, I misinterpreted the part of the standard in question. It says:
"A using-declaration that brings in from a base class an assignment
operator with a parameter type that could be that of a
__copy-assignment
operator__ for the derived class is not considered an explicit
declaration of a copy-assignment operator and does not suppress the
implicit declaration of the the derived class copy-assignment
operator; the operator introduced by the using-declaration is hidden
by the implicitly-declared copy-assignment operator in the derived
class."
Notice that this is only valid whenever there's a *copy* assignment
operator being put into scope by a using-declaration. So, in your
case, the using-declaration puts all operator= of the base class
except for any copy assignment operators (if there were any) into the
scope of the derived class. Therefore, since now there's a
operator=(int) in your derived class, assigning an integer literal to
it is absolutely valid.
Regards,
Sebastian Moleski
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Gil Shafriri" <gilsh@microsoft.com>
Date: 2000/05/16 Raw View
I could not find out reading the standard if operator= which is not copy
assignment operator
(defined in a base class) is inherited by derived class. Could anybody could
show me the exact point in the standard
that answer this question ?
Thanks,
Gil
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Sebastian Moleski" <sebmol@gmx.net>
Date: 2000/05/17 Raw View
13.5.3 Assignment [over.ass]:
"Because a copy assignment operator= is implicitly declared for a
class if not declared by the user (12.8), a base class assignment
operator is always hidden by the copy assignment operator of the
derived class."
--
Sebastian Moleski
----
The Borland C++ Builder bug lists:
http://www.crosswinds.net/~bcbbugs/
Gil Shafriri <gilsh@microsoft.com> schrieb in im Newsbeitrag:
391eb934$1@news.microsoft.com...
| I could not find out reading the standard if operator= which is not
copy
| assignment operator
| (defined in a base class) is inherited by derived class. Could
anybody could
| show me the exact point in the standard
| that answer this question ?
|
| Thanks,
|
| Gil
|
|
| ---
| [ comp.std.c++ is moderated. To submit articles, try just posting
with ]
| [ your news-reader. If that fails, use
lto:std-c++@ncar.ucar.edu ]
| [ --- Please see the FAQ before
]
| [ FAQ:
y.sgi.com/austern_mti/std-c++/faq.html ]
|
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]