質問

私は私のクラスでは、次のCComPtrオブジェクトとメソッドを定義しています:

private:

    CComPtr<IRawPdu>& getRawPdu();
    // Returns the RawPdu interface pointer from the mRawPdu data member.
    // mRawPdu is initialized, if necessary.

    CComPtr<IRawPdu> mRawPdu;
    // Initialized to 0 in the ctor.  Uses lazy evaluation via getRawPdu().

私のクラスのコンストラクタで、私はinitialisorリストを経て0にmRawPduを初期化します。 getRawPdu()がまだ初期化されなければならない場合mRawPdu方法は、遅延評価を使用する。

のコードをコンパイルするとき、私は次のエラーを取得します:

Compiling...
topport.cpp
C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\atlcomcli.h(295) : error C2664: 'ATL::AtlComPtrAssign' : cannot convert parameter 2 from 'const ATL::CComPtr<T>' to 'IUnknown *'
        with
        [
            T=IRawPdu
        ]
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
        C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\atlcomcli.h(292) : while compiling class template member function 'IRawPdu *ATL::CComPtr<T>::operator =(const ATL::CComPtr<T> &) throw()'
        with
        [
            T=IRawPdu
        ]
        sessionutilities.h(186) : see reference to class template instantiation 'ATL::CComPtr<T>' being compiled
        with
        [
            T=IRawPdu
        ]
topglobals.cpp
C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\atlcomcli.h(295) : error C2664: 'ATL::AtlComPtrAssign' : cannot convert parameter 2 from 'const ATL::CComPtr<T>' to 'IUnknown *'
        with
        [
            T=IRawPdu
        ]
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
        C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include\atlcomcli.h(292) : while compiling class template member function 'IRawPdu *ATL::CComPtr<T>::operator =(const ATL::CComPtr<T> &) throw()'
        with
        [
            T=IRawPdu
        ]
        sessionutilities.h(186) : see reference to class template instantiation 'ATL::CComPtr<T>' being compiled
        with
        [
            T=IRawPdu
        ]

これを引き起こしている可能性がどのようにのように任意の提案ですか?

役に立ちましたか?

解決

IRawPduとIUnknownの間の変換を推測することができないことが表示されます、コンパイラによって与えられた誤差に基づいています。

これは実際のIUnknownから継承していますか?もしそうなら、それは問題を発注含ま可能性があります。あなたがIRawPduの階層に多くの洞察力を与えることができます。

他のヒント

必要はありませんから、単にインターフェイスへのポインタを返すCComPtr <>の周りを渡さないでください。たとえばます:

  IRawPdu* getRawPdu() { return mRawPdu; }   // Does not add to the reference count

  HRESULT get_RawPdu(IRawPdu** ppPdu)   // Returns RawPdu, but add ref's it.
  {
     return mRawPdu.CopyTo(ppPdu);
  }

  CComPtr<IRawPdu> mRawPdu;
  // Initialized to 0 in the ctor.  Uses lazy evaluation via getRawPdu().

だから、それはそれを使用する時間が来るときます:

  IRawPdu* pTempRawPdu  = class->getRawPdu();
  // use pTempRawPdu in a temporary manner (since it's not add reffed)

しかし、より良いでしょう。

  CComPtr<IRawPdu> spRawPdu = class->getRawPdu();
  // the ctor of the local CComPtr<> calls AddRef() (and automagically Release's when done)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top