4

私は持っている:

class A : public std::enable_shared_from_this<A>
{...};

class B : public A
{...}; 

void doCoolStuff(std::weak_ptr<A> obj)
{...}

void doCoolStuff(std::weak_ptr<B> obj)
{
 ...
 doCoolStuff(std::static_pointer_cast<A>(obj.lock())); (1)
}

そして B 関数で:

void B::doReallyCoolStuff()
{
 doCoolStuff(std::static_pointer_cast<B>(shared_from_this())); (2)
}

したがって、問題は次のとおりです。

  1. コンパイラ エラー:error C2440: 'static_cast' : cannot convert from 'B *const ' to 'A *'
  2. コンパイラ エラー:error C2668: ambiguous call to overloaded function

次の理由により、どちらも解決する方法がわかりません。

  1. これはconst pointerであるため、何らかの方法で shared_from_this と接続されていると思います。しかし、const_cast なしでこの状況を処理する方法がわかりません。
  2. 関数がさまざまな種類の弱いポインターによってオーバーロードされる可能性があるかどうかはわかりません。

ビルド環境: MSVS 2013 Express

助けてください。ありがとうございました

4

2 に答える 2