Topic: using declarations and ptmf
Author: wmm@fastdial.net
Date: 1999/07/26 Raw View
In article <B3BA79ED-AA977@192.168.1.8>,
"Gabor Greif" <gabor@no.netopia.com> wrote:
> On Tue, Jul 20, 1999 17:37 Uhr, fvali@biotrack.com
> <mailto:fvali@biotrack.com> wrote:
> struct A
> {
> void foo(void);
> };
>
> struct B : A
> {
> using A::foo;
> };
>
> introduces a member function foo in the class B.
>
> However it is not clear to me what the type of a pointer-to-member-
function
> of &B::foo is.
>
> Is it
>
> void (B::*)(void)
>
> or
>
> void (A::*)(void)
> ?
>
> I guess the first, because the type of the 'this' pointer will be
adjusted
> (7.3.3/14)
> to B* accordingly, but OTOH the standard also says that B::foo is
simply an
> alias to A::foo (7.3.3/9).
It's void (A::*)(void). According to 7.3.3p13, it's only for
purposes of overload resolution that the type of "this" is
adjusted. However, "This has no effect on the type of the
function, and in all other respects the function remains a
member of the base class." Thus the expression &B::foo is
treated the same as if the using-declaration were not present,
and according to 5.3.1p2, the type of the address of a base
class member named using a qualified-id whose nested-name-
specifier nominates a derived class is still a pointer to
member of the base class.
> Does the situation change if foo was declared virtual in A?
No.
--
William M. Miller, wmm@fastdial.net
Software Emancipation Technology (www.setech.com)
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
---
[ 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: "Gabor Greif" <gabor@no.netopia.com>
Date: 1999/07/23 Raw View
On Tue, Jul 20, 1999 17:37 Uhr, fvali@biotrack.com
<mailto:fvali@biotrack.com> wrote:
>>
>> Hello,
>>
>> if I read the standard correctly, then a using declaration of this
>form:
>>
>> struct A
>> {
>> void foo(void);
>> };
>>
>> struct B
>> {
>> using A::foo;
>> };
>>
>> introduces a member function foo in the class B.
>
>Actually according to the standard this code is ill-formed since
>using-declarations used as member-declarations must refer to members of
>the base class. Since A is not a base of B the member-declaration is
>ill-formed.
>Refer to section 7.3.3 of the c++ standard for details.
>Particularly paragraphs: 4, 6, 12,13,14 in that section.
>
>regards,
>-fais
>
Ooops, thanks for pointing out my error, of course I intended B to be a
subclass of A!
So let's pose the question again...
struct A
{
void foo(void);
};
struct B : A
{
using A::foo;
};
introduces a member function foo in the class B.
However it is not clear to me what the type of a pointer-to-member-function
of &B::foo is.
Is it
void (B::*)(void)
or
void (A::*)(void)
?
I guess the first, because the type of the 'this' pointer will be adjusted
(7.3.3/14)
to B* accordingly, but OTOH the standard also says that B::foo is simply an
alias to A::foo (7.3.3/9).
Does the situation change if foo was declared virtual in A?
Thanks,
Gabor
---
[ 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: "Gabor Greif" <gabor@no.netopia.com>
Date: 1999/07/19 Raw View
Hello,
if I read the standard correctly, then a using declaration of this form:
struct A
{
void foo(void);
};
struct B
{
using A::foo;
};
introduces a member function foo in the class B.
However it is not clear to me what the type of a pointer-to-member-function
of &B::foo is.
Is it
void (B::*)(void)
or
void (A::*)(void)
?
I guess the first, because the type of the 'this' pointer will be adjusted
to B* accordingly, but OTOH the standard also says that B::foo is simply an
alias to A::foo.
Does the situation change if foo was declared virtual in A?
Thanks,
Gabor
[ 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: fvali@biotrack.com
Date: 1999/07/20 Raw View
In article <7n02ar$dn5$1@rznews.rrze.uni-erlangen.de>,
"Gabor Greif" <gabor@no.netopia.com> wrote:
>
> Hello,
>
> if I read the standard correctly, then a using declaration of this
form:
>
> struct A
> {
> void foo(void);
> };
>
> struct B
> {
> using A::foo;
> };
>
> introduces a member function foo in the class B.
Actually according to the standard this code is ill-formed since
using-declarations used as member-declarations must refer to members of
the base class. Since A is not a base of B the member-declaration is
ill-formed.
Refer to section 7.3.3 of the c++ standard for details.
Particularly paragraphs: 4, 6, 12,13,14 in that section.
regards,
-fais
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
[ 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: gbush@my-deja.com
Date: 1999/07/20 Raw View
In article <7n02ar$dn5$1@rznews.rrze.uni-erlangen.de>,
"Gabor Greif" <gabor@no.netopia.com> wrote:
[snip]
> However it is not clear to me what the type of a pointer-to-member-
function
> of &B::foo is.
>
> Is it
>
> void (B::*)(void)
>
> or
>
> void (A::*)(void)
> ?
>
It's a very interesting question. Can I conclude from 7.3.3p13 that the
type should be that of the derived class?
So I decided to test my compiler (BCB3) and to my surprise it indicates
that the type is A::*
struct A
{
void boo();
};
struct B:A
{
using A::boo;
};
void bar()
{
typedef void Fn();
Fn B::* b_boo = &A::boo; // OK. It's expected.
Fn A::* a_boo = &B::boo; // OK!!!???
}
Gene.
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
---
[ 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 ]