嗨我是一個初學C++開發者..我有一個代碼,我發佈的問題,所以它更容易理解問題。沒有匹配的操作符'='
Obj.h
class Obj : public QObject
{
Q_OBJECT
public:
typedef void (*factionState)();
struct Tran {
factionState Action;
unsigned int nextState;
};
void processAction(myState)
{
Tran const*t = myarrayAction + myState
*(t->action)();
myState=t->nextState;
}
private:
Tran const *myarrayAction;
unsigned int numStates;
protected:
myObj;
myState;
public:
Obj (Tran *arrayAction, const int nStates, const int i) {arrayAction=myarrayAction, numStates = nStates;};
void doNothing(){printf ("Do NOthing called\n")};
Obj_1.h
#include "Obj.h"
const int Obj_1=1
class Obj_1 : public Obj
{
private:
typedef enum {
OffState,
InitState,
RunState,
}state ;
static Obj::Tran myarrayAction[3];
public:
Obj_1() : Obj(myarrayAction, 3, Obj_1) {myState=OffState, myObj=Obj_1,init();};
private:
void init();
void GoToInitState();
void GoToRunState();
};
Obj_1.cpp
void Obj_1::init()
{
myarrayAction[3] = {
{&Obj::doNothing, OffState},
{&Obj_1::GoToInitState, InitState},
{&Obj_1::GoToRunState, RunState},
};
}
void Obj_1::GoToInitState()
{
// code;
}
void Obj_1::GoToRunState()
{
// code;
}
當我構建代碼我有這樣的錯誤:
敵不過「運算符=」(操作數的類型是「的OBJ ::陳」和「」)。於是,我就刪除「=」和寫OBJ1 ::初始化這樣
myarrayAction[3] {
{&Obj::doNothing, OffState},
{&Obj_1::GoToInitState, InitState},
{&Obj_1::GoToRunState, RunState},
};
但我有一個sintax error..Any想法? 謝謝
我不喜歡的語法,但它看起來像你試圖將三個值設置爲一個數組元素..嘗試取出[3]而不是= – CheeseConQueso