Naming is hard Posted June 20, 2006 Report Share Posted June 20, 2006 Hey, heres a peice of code that wont compile the error i get is,"'minus' was not declared in this scope"// pointer to functions#include <iostream>using namespace std;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;}Minus should be global...shouldn't it?If I change:int main (){ int m,n; m = operation (7, 5, addition); n = operation (20, m, minus); cout <<n; return 0;}To:int main (){ int m,n; m = operation (7, 5, addition); n = operation (20, m, subtraction); cout <<n; return 0;}obivouly it works but thats not the point >_< why isn't minus global?btw i got the code from a tutorial located athttp://www.cplusplus.com/doc/tutorial/pointers.html Quote Link to post Share on other sites
jcl Posted June 21, 2006 Report Share Posted June 21, 2006 Compiler and platform? Builds here with Visual C++ and almost with G++. Quote Link to post Share on other sites
Naming is hard Posted June 21, 2006 Author Report Share Posted June 21, 2006 Im using Dev-C++, and i tried in Code::Blocks Quote Link to post Share on other sites
jcl Posted June 21, 2006 Report Share Posted June 21, 2006 Ah. Try renaming minus and see what happens. Quote Link to post Share on other sites
Naming is hard Posted June 21, 2006 Author Report Share Posted June 21, 2006 Ah, that worked, dont get it but it worked. Quote Link to post Share on other sites
iccaros Posted June 21, 2006 Report Share Posted June 21, 2006 it looks like gcc is saying (code blocks and dev-c++ use minigw right which if I remember is gcc on windows)that minus is already a funtion in the std namespacethis is the error I get also declared as `template<class _Tp> struct std::minus' hereso instead of using namespace std;change it to using std::cout; this way you won't pull in the entire namespace just to shortcut cout.. Quote Link to post Share on other sites
jcl Posted June 21, 2006 Report Share Posted June 21, 2006 it looks like gcc is saying (code blocks and dev-c++ use minigw right which if I remember is gcc on windows)that minus is already a funtion in the std namespaceIndeed. It's an STL (Standard Template Library) struct defining a functor (object that acts like a function).so instead of using namespace std;change it to using std::cout;Or qualify the reference to minus in main as ::minus to indicate that you want the one in the global namespace. Quote Link to post Share on other sites
Naming is hard Posted June 21, 2006 Author Report Share Posted June 21, 2006 ahhh, alright thanks Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.