0

なぜ次のスニペットは

#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

?!?

(スニペットはここから取得されます: Build a C++ Add-in for Outlook 2010 )。私の環境:MS Visual Studio 2012 Professional、および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
4

2 に答える 2

1

atlcom.hテンプレートIDispEventSimpleImplが定義されるように含めましたか?テンプレート宣言で使用されている他のクラスの宣言(私はあなたが書いたと思います)は利用できますか?そして、の前方定義でFormRegionWrapperは十分ではないと思います。テンプレートがそれを認識できるように、そのクラスの宣言を含めてみてください。

アップデート

これが大いに役立つかどうかはわかりませんが、ソースをFormRegionWrapper.h以下のコールドに置き換えました(MSDNページの例IDispEventSimpleImpl

#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);
    }
};

これが機能する場合は、テンプレートが正しく含まれていると安全に想定できます。

于 2012-11-07T09:38:24.707 に答える
0

FormRegionWrapper.h の #include ディレクティブの後に次の行を追加します。

名前空間 ATL を使用する。

于 2014-03-08T11:21:42.603 に答える