C2440, Array of functions in a namespace

Theproblem is that I have put all my functions into a seperate .h file in a namespace, none of them are in classes, its a big list of functions in various namespaces which might have been a bad idea but its convenient to the program.

I need to put the functions in the namespace into an array but the dog of a compiler sends me messages of hate and abuse.
It won't let me convert my user defined type (the namespace I assume) into a normal type, something or other to do with a pointer causes the problem, someone please let me know if there's a way to define a way to point to the namespace fn's or if I'm gonna have to put them all into structs or classes. Thanks.

1
2
3
4
5
6
7
8
9
10
// Fn.h is something like
namespace fn {

   int value, value, value etc.

   namespace fnLvl1 {

      int fn(int a); etc.
   }
}


1
2
3
4
5
6
7
8
9
// Fn.cpp overloads all the functions
namespace fn {
   namespace fnLvl1 {

      int fn1(int a) {
         // Do things
         // Return int
   }
}


1
2
3
4
5
6
7
8
// Main needs to store a bunch of these into an array
typedef (*ptrToAFn)(int a);
int main() {
   ptrToAFn fnList[] = {
      fnLvl1::fn1(),
      fnLvl1::fn2() etc;
   };
}


Please note this is just example code that displays the problems I'm having and not the actual code therefore do not tell me to add returns and such things.

Thanks for your help, much appreciated.
Last edited on
If all the functions that you want to put in the array have the same signature there is no problem. Also remove the parenthesis after the name of the functions

Try somethink like this :

1
2
3
4
5
6
7
8
9
10

typedef int (*ptrToAFn)(int);

int main() {
    ptrToAFn fnList[] = {
      fnLvl1::fn1,
      fnLvl1::fn2
   };
}
Perfect, works nicely!!! Thanks alot!!!
Topic archived. No new replies allowed.