1
我得到以下鏈接錯誤:爲什麼我會收到這些鏈接器錯誤?
Error 1 error LNK2001: unresolved external symbol "public: __thiscall AguiEvent<class AguiEmptyEventArgs>::AguiEvent<class AguiEmptyEventArgs>(void)" ([email protected]@@@@[email protected]) AguiWidgetBase.obj
Error 2 error LNK2001: unresolved external symbol "public: void __thiscall AguiEvent<class AguiEmptyEventArgs>::call(class AguiEmptyEventArgs)" ([email protected][email protected]@@@@[email protected]@@Z) AguiWidgetBase.obj
Error 3 error LNK2001: unresolved external symbol "public: __thiscall AguiEvent<class AguiControlEventArgs>::AguiEvent<class AguiControlEventArgs>(void)" ([email protected]@@@@[email protected]) AguiWidgetBase.obj
Error 4 error LNK2001: unresolved external symbol "public: void __thiscall AguiEvent<class AguiControlEventArgs>::call(class AguiControlEventArgs)" ([email protected][email protected]@@@@[email protected]@@Z) AguiWidgetBase.obj
Error 5 fatal error LNK1120: 4 unresolved externals C:\Users\Josh\Documents\Visual Studio 2008\Projects\Agui\STATIC Release\Agui.exe
我有AguiEventArgs.h其中有這樣的:
class AguiWidgetBase;
class AguiEmptyEventArgs {
public:
AguiEmptyEventArgs();
};
class AguiMouseEventArgs {
AguiPoint position;
int mouseWheelChange;
AguiMouseButtonEnum button;
public:
AguiPoint getPosition() const;
int getMouseWheelChange() const;
AguiMouseButtonEnum getButton() const;
int getX() const;
int getY() const;
AguiMouseEventArgs();
AguiMouseEventArgs(const AguiPoint &position,
int mouseWheelChange, AguiMouseButtonEnum button);
};
class AguiKeyEventArgs {
AguiKeyEnum key;
AguiKeyModifierEnum modKey;
bool isAlt;
bool isControl;
bool isShift;
public:
bool getAlt() const;
bool getControl() const;
bool getShift() const;
AguiKeyEnum getKey() const;
AguiKeyModifierEnum getModifierKeyFlags() const;
AguiKeyEventArgs();
AguiKeyEventArgs(AguiKeyEnum key, AguiKeyModifierEnum modKey);
};
class AguiControlEventArgs {
AguiWidgetBase* control;
public:
AguiWidgetBase* getControl() const;
AguiControlEventArgs();
AguiControlEventArgs(AguiWidgetBase* control);
};
我有雙重檢查和確定所有這些。
我阿桂事件是在這裏:
template <typename T>
class AguiEvent {
void (*onEvent)(T arg);
public:
void setHandler(void (*eventProc)(T arg));
void removeHandler();
void call(T arg);
AguiEvent();
};
其定義爲:
template <typename T>
void AguiEvent<T>::setHandler(void (*eventProc)(T arg))
{
onEvent = eventProc;
}
template <typename T>
void AguiEvent<T>::removeHandler()
{
onEvent = 0;
}
template <typename T>
void AguiEvent<T>::call(T arg)
{
if(onEvent)
onEvent(arg);
}
template <typename T>
AguiEvent<T>::AguiEvent()
{
onEvent = 0;
}
它這樣使用:
AguiEvent<AguiEmptyEventArgs> eventThemeChanged;
AguiEvent<AguiControlEventArgs> eventChildControlAdded;
AguiEvent<AguiControlEventArgs> eventChildControlRemoved;
例如:
void AguiWidgetBase::addChildControl(AguiWidgetBase *control)
{
onAddChildControl(control);
eventChildControlAdded.call(AguiControlEventArgs(control));
}
謝謝
哦好吧謝謝。 – jmasterx 2010-10-10 19:11:38
出口不是非標準的,至少對於今天來說。同意一切,但 – 2010-10-10 19:13:13
只是把它拿出來的CPP,它的工作 – jmasterx 2010-10-10 19:14:37