Question: Consider the following classes:

```
class MyInterface1 {
    ...
};
class MyInterface2 {
    ...
};
class MyClass : public MyInterface1, public MyInterface2 {
    ...
};

```

If I have the following code:

```
void MyFunction(shared_ptr<MyInterface1>& out); // returns a make_shared<MyClass>

shared_ptr<MyInterface1> c1;
shared_ptr<MyInterface2> c2;
MyFunction(c1);
c2 = c1;

```

I'm unable to assign c2 to c1. 

Additionally, it also won't compile if I just call `MyFunction(c2)`, which I would expect to work since MyClass is derived from both MyInterface1 and MyInterface2. This seems like a compiler bug (Visual Studio 2015 Update 3) that might be worth sharing. Can anyone reproduce this?

Answer: 
`MyInterface1` and `MyInterface2` are totally unrelated types. Just because the object pointed to by `c1` has a runtime type that inherits from both, the static types are incompatible and you will have to use a cast to assign one to the other

```
shared_ptr<MyInterface1> c1;
shared_ptr<MyInterface2> c2;
MyFunction(c1);
c2 = dynamic_pointer_cast<MyInterface2>(c1);

```

[Live Example](http://coliru.stacked-crooked.com/a/d13a69d4e44cd78c)

This will, of course, only work if the actual dynamic type of `*c1` inherits from `MyInterface2`. Like any `dynamic_cast`, [`dynamic_pointer_cast`](http://en.cppreference.com/w/cpp/memory/shared_ptr/pointer_cast) will return `nullptr` if the types are incompatible.
You can do this with raw pointers but it's not possible to do with a shared\_ptr. Don't use shared\_ptr, but instead do this:

```
void MyFunction(MyInterface1* out); // returns a new MyClass()

MyInterface1* c1;
MyInterface2* c2;
MyFunction(c1);
c2 = (MyInterface2*)c1;
MyFunction((MyInterface1*)c2);

```

It's certainly a lot cleaner, easier and more maintainable. Also its faster since you're not using shared\_ptr anymore and has less overhead. Don't use shared\_ptr if you care about performance.