vendredi 29 septembre 2017

How do I create and array of pointers to functions?

gcc 6.4.0 win 7 Netbeans 8.2

I can't figure what I'm doing wrong.

#ifndef TYPEDEF_H
#define TYPEDEF_H

class Typedef {
   class Alphabet { };
   class Tuple { };
   class Operations { };
public:
   void test();
private:
   Tuple constant(long one, long two, Alphabet& bet, Operations& op) { return Tuple(); } ;
   Tuple expression(long one, long two, Alphabet& bet, Operations& op) {return Tuple(); } ;
};

#endif /* TYPEDEF_H */

===================== .cpp file ========================
#include "Typedef.h"

void Typedef::test() {
   typedef Tuple (*fn)(long, long, Alphabet&, Operations&);
   fn func[]      = { constant, expression };
   Tuple (*fnc[2])= { constant, expression };
}

Typedef.cpp: In member function 'void Typedef::test()':

Typedef.cpp:6:44: error: cannot convert 'Typedef::constant' from type 'Typedef::Tuple (Typedef::)(long int, long int, Typedef::Alphabet&, Typedef::Operations&)' to type 'fn {aka Typedef::Tuple (*)(long int, long int, Typedef::Alphabet&, Typedef::Operations&)}' fn func[] = { constant, expression };

The error message is repeated for all four instances. I've tried &constant and as expected it didn't work.

Aucun commentaire:

Enregistrer un commentaire