Quantcast
Channel: C++ cannot convert from base A to derived type B via virtual base A - Stack Overflow
Browsing all 8 articles
Browse latest View live

Answer by CoffeDeveloper for C++ cannot convert from base A to derived type B...

I don't know if this is "safe" but.AssumingB derived from A (and A pure virtual)Since I KNOW that a pointer to B still remains a pointer to B. class A { virtual void doSomething(const void* p) const...

View Article



Answer by Chubsdad for C++ cannot convert from base A to derived type B via...

$5.2.9/2- "An expression e can be explicitly converted to a type T using a static_cast of the form static_cast(e) if the declaration“T t(e);” is well-formed, for some invented temporary variable t...

View Article

Answer by Matthieu M. for C++ cannot convert from base A to derived type B...

In order to understand the cast system, you need to dive into the object model.The classic representation of a simple hierarchy model is containment: if B derives from A then the B object will, in...

View Article

Answer by liaK for C++ cannot convert from base A to derived type B via...

According standard docs,Section 5.2.9 - 9, for Static Cast,An rvalue of type “pointer to cv1 B,” where B is a class type, can be converted to an rvalue of type “pointer to cv2 D,” where D is a class...

View Article

Answer by Nico for C++ cannot convert from base A to derived type B via...

Yes, you have to use a dynamic_cast, but you'll have to make the base class A polymorphic, e.g. by adding a virtual dtor.

View Article


Answer by Yakov Galka for C++ cannot convert from base A to derived type B...

You can't use static_cast in this situation because the compiler doesn't know the offset of B relative to A at compile time. The offset must be calculated at run-time based on the exact type of the...

View Article

Answer by Jon Purdy for C++ cannot convert from base A to derived type B via...

As far as I know, you need to use dynamic_cast because the inheritance is virtual and you're downcasting.

View Article

C++ cannot convert from base A to derived type B via virtual base A

I have four classes:class A {};class B : virtual public A {};class C : virtual public A {};class D: public B, public C {};Attempting a static cast from A* to B* I get the below error:cannot convert...

View Article

Browsing all 8 articles
Browse latest View live




Latest Images