I have:
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)
}
And then in B function:
void B::doReallyCoolStuff()
{
doCoolStuff(std::static_pointer_cast<B>(shared_from_this())); (2)
}
So problems are:
- Compiler error:
error C2440: 'static_cast' : cannot convert from 'B *const ' to 'A *'
- Compiler error:
error C2668: ambiguous call to overloaded function
I don't understand how to resolve either of them, because:
- I think it's somehow connected with shared_from_this, because this is const pointer. But I don't know how to handle this situation without const_cast.
- I don't know if functions can be overloaded by different types of weak pointers.
Build environment: MSVS 2013 express
Please, help. Thank you