Article View: gnu.g++.help
Article #239Re: how to do this?
From: Jonas Svanberg
Date: Sat, 12 Sep 1992 16:00
Date: Sat, 12 Sep 1992 16:00
34 lines
1656 bytes
1656 bytes
> What is wrong with the
> following constructions and how can I do it in g++?
>
> ----------
>
> class a {
> public:
> int x();
> };
>
> int a::x() { return 1; }
>
> main() {
> printf("%x\n", (int(*))a::x);
> }
You're trying to cast a pointer to member to a pointer to object
type. That can't be done according to the standards
documentation I've read over C++ (Annotated C++ Ref. Man. by
Ellis & Stroustrup).
Pointer to members may even not be explicitly converted to void*!
The reason for this is that pointers to members may be
a structure containing both addresses and offsets. There is
no point in allowing a cast to any ordinary pointer.
O----------------------------O----------------------------------O
| Jonas Svanberg | Email: svan@isy.liu.se |
| Div. of Information Theory O----------------------------------O
| Department of E.E. (ISY) | "And Noah said to the animals: |
| Linkoping University | - Go out and multiply! |
| S-581 83 Linkoping | The snake said: |
| SWEDEN | - But how can I? I'm an adder!" |
O----------------------------O----------------------------------O
Technical Details
Message-ID:
<1992Sep12.160053.28778@isy.liu.se>Path:
arc1-ca.pugleaf.net!sparky!uunet!mcsun!sunic!liuida!isy!isy.liu.se!svanReferences:
<92Sep10.203359.4881@acs.ucalgary.ca>Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.help Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sunic!liuida!isy!isy.liu.se!svan From: svan@isy.liu.se (Jonas Svanberg) Subject: Re: how to do this? Message-ID: <1992Sep12.160053.28778@isy.liu.se> Keywords: pointer to member Sender: news@isy.liu.se (Lord of the News) Reply-To: svan@isy.liu.se Organization: Linkoping University References: <92Sep10.203359.4881@acs.ucalgary.ca> Date: Sat, 12 Sep 1992 16:00:53 GMT Lines: 35