Reputation: 718
Say I have a class A
under namespace AAA
with a definition like this:
namespace AAA {
class A
{
int x;
std::vector<double> y;
A* ptr;
};
}
And I have another class B
with the same structure as follow but it is under a different namespace BBB
,
namespace BBB {
class B
{
int x;
std::vector<double> y;
B* ptr;
};
}
I know the correct way to do this is to have only one definition in the first place but now let's assume we can't change that fact that there is an AAA::A
class and a BBB::B
class. Is there a way I can convert an A
object to a B
object?
Upvotes: 4
Views: 1280
Reputation:
There is no safe conversion whatsoever. The best is a static_assert(sizeof(A) == sizeof(B), "Different Size") followed by a brave reinterpret_cast.
Upvotes: 4