Questions tagged [cross-cast]
4 questions
10
votes
4 answers
Complex dynamic_cast in c++
I have the following case in C++:
Abstract base classes Abstract1 and Abstract2. They are unrelated.
A class Foo deriving from both Abstract1 and Abstract2
I am in a compilation unit where I have no information about class Foo (no declaration, no…

galinette
- 8,896
- 2
- 36
- 87
8
votes
3 answers
Checking whether a cross-cast could possibly work?
I know that it's legal to use dynamic_cast to do a "cross-cast" across a class hierarchy. For example, if I have classes that look like this:
A B
\ /
C
If I have an A* pointer that's pointing at an object of type C, then I can use
A*…

templatetypedef
- 362,284
- 104
- 897
- 1,065
2
votes
1 answer
What's faster: down-cast from virtual base or cross-cast?
This is somewhat hypothetical as I'm not too worried about performance - just wondering which option is actually the fastest/most efficient in general, or if there is no difference whatsoever.
Suppose I have the following code for a visitor template…

Pete
- 4,784
- 26
- 33
0
votes
1 answer
Why is this cross-cast not allowed?
Consider this simple example:
struct Base1 {};
struct Base2 {};
struct Derived : public Base1, public Base2 {};
int main()
{
Derived foo;
Base1* foo1 = &foo;
Base2* foo2 = static_cast(foo1);
}
I get:
Error: static_cast from…

yggdrasil
- 737
- 5
- 14