Topic: Is it allowed in std or only VC++ 6.0 allows it


Author: williamb@airmail.net (William H. Bloodworth)
Date: 1999/08/08
Raw View
On 02 Aug 99 04:42:31 GMT, "Karthi" <karthitu@eth.net> wrote:

I am unable to get your code below to even compile.  In the line where you state "// but
this OK?", you typecast to (A::pf).  'A' does not have a member function pf.  I still
don't see how you're able to cast something that you don't have access to.  You'll get an
error from the compiler about not having access to the private member before it ever
attempts to cast the function pointer.

If I missed something here, please show me the err of my ways.

William Bloodworth

>Hi,
>
>I'm able to access the private function of an object by typecasting it to a
>function pointer and calling the pointer.
>
>class A {
>    void foo(int a) {.}
>};
>..
>// void (A::*pf)(int) = A::foo; // says private functon
>
>void (A::*pf)(int) = (A::pf)(int)A::foo; // but this OK?
>A a;
>a.*pf(5);
>
>If it is the case how the privacy is maintained
>
>Karthi

[ 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: "Karthi" <karthitu@eth.net>
Date: 1999/08/02
Raw View
Hi,

I'm able to access the private function of an object by typecasting it to a
function pointer and calling the pointer.

class A {
    void foo(int a) {.}
};
..
// void (A::*pf)(int) = A::foo; // says private functon

void (A::*pf)(int) = (A::pf)(int)A::foo; // but this OK?
A a;
a.*pf(5);

If it is the case how the privacy is maintained

Karthi
---
[ 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              ]