首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >可视化C++:C2143

可视化C++:C2143
EN

Stack Overflow用户
提问于 2012-11-07 17:24:03
回答 2查看 588关注 0票数 0

为什么下面的代码片段

代码语言:javascript
复制
#include <atlcom.h>
...
class FormRegionWrapper;
...
// Errorsource :
typedef IDispEventSimpleImpl
        <2, FormRegionWrapper, &__uuidof(FormRegionEvents)> 
        FormRegionEventSink;

将显示以下错误:

代码语言:javascript
复制
// 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的帮助信息:

代码语言:javascript
复制
// 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
EN

回答 2

Stack Overflow用户

发布于 2012-11-07 17:38:25

为了定义模板IDispEventSimpleImpl,您是否包含了atlcom.h?在模板声明中使用的其他类的声明(我假设是由您编写的)是否可用?我认为FormRegionWrapper的正向定义还不够,你能试着包含那个类的声明,这样模板就能看到它吗?

更新

不确定这是否会有很大帮助,但我用下面的colde替换了FormRegionWrapper.h的源代码(来自IDispEventSimpleImpl上的MSDN页面的示例

代码语言:javascript
复制
#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);
    }
};

如果这样做有效,您可以放心地假定模板已被正确包含。

票数 1
EN

Stack Overflow用户

发布于 2014-03-08 19:21:43

在FormRegionWrapper.h中的#include指令之后添加以下行:

使用命名空间ATL;

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13266665

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档