[comp.sys.amiga] help: C++

c150-ec@danube.Berkeley.EDU (Johnson Sieu) (10/01/90)

   I wanted to define a function that accepts a function pointer in C++
   and the compiler complained.  My program is as follows:

   void foo ()
   {
   }

   void foobar(void (*func)())
   {
	void (*temp_func)();

	temp_func = func;
   }

   int main()
   {
	foobar(&foo);
   }

   The compiler doesn't seem to accept my argument declaration for func!
   I compiled it under Lattice C and everything is fine.  What is the 
   problem then?  Could any experienced C++ programmer please help me to see
   the light.  


   Johnson
   email:  c150-ec@danube.berkeley.edu

daveh@cbmvax.commodore.com (Dave Haynie) (10/03/90)

In article <28364@pasteur.Berkeley.EDU> c150-ec@danube.Berkeley.EDU.UUCP (Johnson Sieu) writes:

>   I wanted to define a function that accepts a function pointer in C++
>   and the compiler complained.  [..program deleted.. ]

>   The compiler doesn't seem to accept my argument declaration for func!
>   I compiled it under Lattice C and everything is fine.  What is the 
>   problem then?  Could any experienced C++ programmer please help me to see
>   the light.  

In C++, you need a typedef for a function pointer type to be passed around.
In your case, if you did something like:

	typedef	void *voidfunptr(void);

then you could legally do things like:

	void thing(voidfuncptr A) {
	    voidfuncptr B = A;

	    // .....
	}

Etc. and so forth.

>   Johnson

-- 
Dave Haynie Commodore-Amiga (Amiga 3000) "The Crew That Never Rests"
   {uunet|pyramid|rutgers}!cbmvax!daveh      PLINK: hazy     BIX: hazy
	Standing on the shoulders of giants leaves me cold	-REM