我有一个全局声明的静态函数需要引用一个对象,但是当我这样做时,我得到一个“未声明的标识符”错误。
这是我的代码示例
#pragma once
#include "stdafx.h"
#include <vector>
#include "Trigger.h"
using namespace std;
namespace Gamma_Globals
{
static vector<void*> gvTriggers;
}
static LPARAM CALLBACK ProgramWndProc(HWND, UINT, WPARAM, LPARAM);
static LPARAM CALLBACK ProgramWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_KEYUP:
{
for (int i = 0; i < Gamma_Globals::gvTriggers.size(); i++)
{
Trigger t = Gamma_Globals::gvTriggers[i];
}
}
default: return DefWindowProc(hWnd, uMsg, wParam, lParam); break;
}
return 0;
}
问题出现在 WM_KEYUP 案例中,当我尝试设置“触发器 t”时,我收到错误“'触发器':未声明的标识符。” 如何从 ProgramWndProc 引用 Trigger 对象?
谢谢!
根据要求,这是 Trigger.h 的副本
#pragma once
#include "Noun.h"
#include "TermFactory.h"
#include "Globals.h"
using namespace std;
class Trigger
{
public:
enum TRIGGER_TYPE {NONE, ONKEYPRESS, ONMOUSEPRESS};
Trigger(void*);
Trigger(LPTSTR trigger, LPTSTR action, Gamma_Globals::TRIGGER_TIME);
~Trigger(void);
VOID Perform();
TRIGGER_TYPE GetType();
private:
LPTSTR lpCondition;
LPTSTR lpAction;
Gamma_Globals::TRIGGER_TIME triggerTime;
vector<Noun*> vNouns;
TRIGGER_TYPE triggerType;
VOID LoadAction(LPTSTR Action);
HRESULT LoadCondition(LPTSTR Condition);
};