dynamic-cast

Inheritance and pointers to pointers: why doesn't it work and how do I get around it?

Why do I get a compilation error when I call a base-class function with a pointer to a pointer to an inherited class? Example: class cFoo {}; class cBar : public cFoo {}; void func1(cFoo *) {} // base class void func2(cFoo **) {} // base class void main(void) { cBar bar, *pbar; // inherited class func1(&bar); // compiles ...

C++ - downcasting a diamond shape inherited object without RTTI/dynamic_cast

Hi all! I'm currently working on integrating a third-party package that uses lots of RTTI stuff on a non-RTTI platform (Android). Basically, I did my own RTTI implementation but I'm stuck on a problem. The issue is that a lot of classes are having the diamond inheritance problem since all the classes derive from the same base class (ob...

Can I teach dynamic_cast<>() new tricks?

Is there a way in C++ to construct your class such that given a pointer to your class you can instruct dynamic_cast<>() how to cast to another class for which you are wrapping the implementation? Would operator cast do the trick? Imagine I have an Abstract interface base class and derive a concreteA from this as well as concreteB, but ...

Dynamic cast and multiple inheritance

The dynamic_cast operator is returning zero (0) when I apply to a pointer that points to an instance of a multiply inherited object. I don't understand why. The hierarchy: class Field_Interface { public: virtual const std::string get_field_name(void) const = 0; // Just to make the class abstract. }; class Record_ID_Interface {...

What is the difference between static and dynamic cast in c++?

Possible Duplicate: Regular cast vs. static_cast vs. dynamic_cast what is difference between static and dynamic cast in c++? ...

C++ downcast ( using dynamic_cast ) returns NULL ?

Environment: Linux C++ / Qt 4x I do not understand why the following downcast returns NULL? I pasted base and derived class below. Thanks in advance for any tips or suggestions. -Ed void MainWindow::onRtledaEventHandler(fes::EventArgs eventArgs) { // This cast returns a NULL ? fes::AtsCommandEventArgs* atsCommandEventArgs = d...

cast const Class using dynamic_cast

I want to cast this: class Base { public: virtual ~Base(){}; }; class Der : public Base {}; int main() { const Base* base = new Der; Der* der = dynamic_cast<Der*>(base); // Error return 0; } What should I do? I tried to put: const Der* der = dynamic_cast<Der*>(base); to mantain the const but this doesn't work. ...

Supporting artificial "casting" of generated .Net types

(I applogise in advance for the length of this post, however the problem is fairly complex - hopefully everything is clear however I have simplified the scenario a lot and so there is a good chance that I've missed a vital fact, or there is something that I've not explained.) Setting the scene I'm using code generation to generate C# w...

Is it possible to dynamic_cast from one base class to another?

For instance I have code like that class Base1 { virtual void wonderFULL() = 0; }; class Base2 { // all this weird members }; class Derived : public Base1, public Base2 { // not so weird members }; int main() { Derived Wonder; magicFunction(&Wonder); return 0; } void magicFunction(Base2 *ptr) { if (Base1 *b1 = dynamic_...

In C++ check if two instances of a base class are infact of the same subclass.

The below code explains the problem. Fill in same_sub_class to detect if the two pointers to virtual base class A are in fact the same concrete class. struct A { ... }: struct B : public A { ... }: struct C : public A { ... } bool same_sub_class(A * a1, A * a2){ // Fill this in to return true if a1 and a2 are //...

java: combined instanceof and cast ?

(Please no advise that I should abstract X more and add another method to it.) In C++, when I have a variable x of type X* and I want to do something specific if it is also of type Y* (Y being a subclass of X), I am writing this: if(Y* y = dynamic_cast<Y*>(x)) { // now do sth with y } The same thing seems not possible in Java (or...

how does dynamic_cast work internally?

Possible Duplicate: How is dynamic_cast typically implemented? Hi! how does dynamic_cast actually work? where does the runtime know from whether some piece of memory actually fits the datatype or not? Thanks! ...

Performance of dynamic_cast?

Before reading the question: This question is not about how useful it is to use dynamic_cast. Its just about its performance. I've recently developed a design where dynamic_cast is used a lot. When discussing it with co-workers almost everyone says that dynamic_cast shouldn't be used because of its bad performance (these are co-workers ...