为什么下面的代码片段
#include <atlcom.h>
...
class FormRegionWrapper;
...
// Errorsource :
typedef IDispEventSimpleImpl
<2, FormRegionWrapper, &__uuidof(FormRegionEvents)>
FormRegionEventSink;将显示以下错误:
// Error ouput:
error C2143: syntax error : missing ';' before '<'
error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int?!?
(截图摘自此处:Building a C++ Add-in for Outlook 2010 )。我的环境: MS Visual Studio 2012专业版和Windows 7-64。
PS 1:下面是关于IDispEventSimpleImpl的帮助信息:
// Help IDispEventSimpleImpl Class : This class provides implementations of
// the IDispatch methods, without getting type information from a type library.
// template <
// UINT nID,
// class T,
// const IID* pdiid
// >
// class ATL_NO_VTABLE IDispEventSimpleImpl :
// public _IDispEventLocator<nID, pdiid>
//
// Requirements
// -------------------
// Header: atlcom.h发布于 2012-11-07 17:38:25
为了定义模板IDispEventSimpleImpl,您是否包含了atlcom.h?在模板声明中使用的其他类的声明(我假设是由您编写的)是否可用?我认为FormRegionWrapper的正向定义还不够,你能试着包含那个类的声明,这样模板就能看到它吗?
更新
不确定这是否会有很大帮助,但我用下面的colde替换了FormRegionWrapper.h的源代码(来自IDispEventSimpleImpl上的MSDN页面的示例
#pragma once
#include "stdafx.h"
#include <vector>
#include <algorithm>
_ATL_FUNC_INFO Event1Info1 = { CC_CDECL, VT_EMPTY, 1, { VT_I4 } };
class CEventHandler;
typedef IDispEventSimpleImpl <1234, CEventHandler, &__uuidof(IDispatch)>
DummySink;
class CEventHandler : public DummySink
{
public:
BEGIN_SINK_MAP(CEventHandler)
SINK_ENTRY_INFO(1234, __uuidof(IDispatch), 1, OnEvent1, &Event1Info1)
END_SINK_MAP()
void __stdcall OnEvent1(LONG l)
{
//ATLASSERT(l == 445533);
if (l != 445533)
OutputDebugString(L"l is not 445533\n");
}
HRESULT Advise1234(IUnknown * punk) {
return IDispEventSimpleImpl<1234, CEventHandler, &__uuidof(IDispatch)>::DispEventAdvise(punk);
}
};如果这样做有效,您可以放心地假定模板已被正确包含。
发布于 2014-03-08 19:21:43
在FormRegionWrapper.h中的#include指令之后添加以下行:
使用命名空间ATL;
https://stackoverflow.com/questions/13266665
复制相似问题