🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #49756

Re: Function pointer problem

#49756
From: Fergus Henderson
Date: Wed, 15 Dec 1993 10:22
44 lines
1594 bytes
jason@ab02.larc.nasa.gov (Jason Austin) writes:

>class Test {
>public:
>  Test();
>  ~Test();
>
>private:
>  int (*fp)();
>
>  int testfunction();
>};
>
>int Test::testfunction() {}
>
>Test::Test() {
>  fp=testfunction;
>}
>
>Test::~Test() {}
>
>int testfunction() {}
>
>main()
>{
>  int (*fp)();
>
>  fp=testfunction;
>}
>
>	Why does the assignment in main() compile but the one in
>Test::Test() reports "assignment between incompatible pointer types".
>I'm using g++ 2.5.6.  Thanks.

Because Test::testfunction is a (non-static) member function, not an ordinary
function, and you can't assign a pointer to member function to
a pointer to non-member function.  You can get it to work by making
Test::testfunction a static member function.

I suggest that you look up "static member function" and "pointer to
member" in the index of good C++ book.

-- 
Fergus Henderson                     fjh@munta.cs.mu.OZ.AU
Technical Details
Message-ID: <9334921.7238@mulga.cs.mu.OZ.AU>
Path: arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!yale.edu!spool.mu.edu!sgiblab!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
References: <JASON.93Dec13110517@ab02.larc.nasa.gov>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,7995d8ee432feb24
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1993-12-15 02:54:26 PST
Newsgroups: gnu.gcc.help
Path: arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!yale.edu!spool.mu.edu!sgiblab!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Subject: Re: Function pointer problem
Message-ID: <9334921.7238@mulga.cs.mu.OZ.AU>
Sender: news@cs.mu.OZ.AU
Organization: Computer Science, University of Melbourne, Australia
References: <JASON.93Dec13110517@ab02.larc.nasa.gov>
Date: Wed, 15 Dec 1993 10:22:04 GMT
Lines: 44