Topic: ptmf for const this?
Author: bill@gibbons.org (Bill Gibbons)
Date: 1999/04/23 Raw View
In article <B34531FC-19E86D@192.168.1.8>, Gabor Greif
<gabor@no.netopia.com> wrote:
> Is there a provision in the standard for pointer-to-member-functions that
> are "const"?
>
> I guess the syntax would be for example
>
> typedef void (T::*cptmf)(void) const;
>
> My compiler accepts this syntax, though it allows me to pass a ptmf where a
> cptmf is needed (with typedef void (T::*ptmf)(void); ) so I am not
> completely sure.
>
> I suspect this would be a breach of the promise to leave the "this" object
> constant:
>
> struct M
> {
> void bar(void);
> };
>
> static void foo(void (M::*cb)() const)
> {
> const M m;
>
> foo(&M::bar); // should be illegal: ptmf passed where cptmf needed
> // but allowed by my compiler
>
> (m.*cb)(); // should be okay
> (m.*(&M::bar))(); // should be illegal: non-const
member-function
> // invoked on const object
> }
>
>
> Is my reasoning correct?
Yes.
Author: Gabor Greif <gabor@no.netopia.com>
Date: 1999/04/22 Raw View
Is there a provision in the standard for pointer-to-member-functions that
are "const"?
I guess the syntax would be for example
typedef void (T::*cptmf)(void) const;
My compiler accepts this syntax, though it allows me to pass a ptmf where a
cptmf is needed (with typedef void (T::*ptmf)(void); ) so I am not
completely sure.
I suspect this would be a breach of the promise to leave the "this" object
constant:
struct M
{
void bar(void);
};
static void foo(void (M::*cb)() const)
{
const M m;
foo(&M::bar); // should be illegal: ptmf passed where cptmf needed
// but allowed by my compiler
(m.*cb)(); // should be okay
(m.*(&M::bar))(); // should be illegal: non-const member-function
// invoked on const object
}
Is my reasoning correct?
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 ]