help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: pointer to function. why doesn't this compiler


From: Juergen Heinzl
Subject: Re: pointer to function. why doesn't this compiler
Date: Thu, 27 May 2004 21:44:39 +0000 (UTC)
User-agent: slrn/0.9.7.4 (Linux)

In article <vgmcb0panm9atlp5bi95btvt2np7hgg1ok@4ax.com>, 2boxers wrote:
> Can somebody tell me why the following program fails to compile?
> I am using gcc-3.4.0.
> 
> #include <iostream>
> using namespace std;
[-]
Bad idea, because ...

> int addition (int a, int b)
> { return (a+b); }
> 
> int subtraction (int a, int b)
> { return (a-b); }
> 
> int (*minus)(int,int) = subtraction;
> 
> int operation (int x, int y, int (*functocall)(int,int))
> {
>   int g;
>   g = (*functocall)(x,y);
>   return (g);
> }
> 
> int main ()
> {
>   int m,n;
>   m = operation (7, 5, addition);
>   n = operation (20, m, minus);
>   cout <<n;
>   return 0;
> }
> 
> here is what i get when i try to compile:
> g++ pointer4.cpp -o pointer4
> 
> pointer4.cpp: In function `int main()':
> pointer4.cpp:23: error: `minus' undeclared (first use this function)
> pointer4.cpp:23: error: (Each undeclared identifier is reported only
> once for each function it appears in.)
[-]
... minus is also a STL function object.

> Thanks in advance for any suggestions,
[-]
Either don't use using namespace std a./o. put your stuff into a separate
namespace (you know what namespaces are good for now ;-) ) or use a
different naming scheme like minus_( ... ) of minus_fp( ... ).

The namespace solution is the most flexible, though,
Juergen

-- 
\ Real name     : Juergen Heinzl       \       no flames      /
 \ Email private : juergen@manannan.org \ send money instead /
  \ Photo gallery : www.manannan.org     \                  /


reply via email to

[Prev in Thread] Current Thread [Next in Thread]