gcc 6.4.0 win 7 Netbeans 8.2如何創建和指向函數的指針數組?
我無法弄清楚我做錯了什麼。重複
#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 };
該錯誤消息的所有四個實例。我試過&不變,並預期它沒有工作。
成員函數不是函數... –
您可能感興趣的['標準:: function'(http://en.cppreference.com/w/cpp/utility/functional/function)。 –