David Harmon wrote:
On 27 Nov 2006 03:22:22 -0800 in comp.lang.c++,
Ma*************@gmail.com wrote,
I was hopeing that there was some way i could say in the constructor
don't use a new instance of the base class, use this one that is
already made, otherwise I am copping allot of code over and over again.
A new instance of a derived class always contains a new instance of its
base class. But that's no reason to copy code. Why are you copying
code?
As for the constructor, you use the base copy constructor in the derived
constructor initializer list, right?
Oooo I see what you're saying, No I wasn't I was storing the base
instnace and then forwarding the call to the base... This was because
I needed certain calls to be caughed by the active part of an object if
it was a physics active object as opposed to a physics object, so....
/************************************************** ************************/
/* Physics Entity, Serves as a Wraper class for Mobile Entity allowing
*/
/* Collision detection and apropriate responce control, however it
still */
/* inherits from Entity so it can be added to a display queue without
*/
/* having to grab internal data */
/************************************************** ************************/
class PhysicsEntity {//: public Entity {
protected:
PhysicsEntity();
public:
bool Coliding(PhysicsEntity* other);
private:
D3DXVECTOR3 __GetCenter();
float __radius;
D3DXVECTOR3 __absCenter;
};
class MobilePhysicsEntity: public MobileMesh, public PhysicsEntity {
public:
MobilePhysicsEntity(MobileEntity* base);
~MobilePhysicsEntity() {}
/* Mobile Entity Members
************************************************** *****************/
public:
virtual void WorldRelTran(float x, float y, float z) {
__base->WorldRelTran(x,y,z); }
virtual void WorldRelScale(float x, float y, float z)
{__base->WorldRelScale(x,y,z);}
public:
virtual void SetAbsTran(float x, float y, float z)
{__base->SetAbsTran(x,y,z);}
virtual void SetAbsRot(float x, float y, float z)
{__base->SetAbsRot(x,y,z);}
virtual void SetAbsScale(float x, float y, float z)
{__base->SetAbsScale(x,y,z);}
public:
virtual void RelTran(float x, float y, float z)
{__base->RelTran(x,y,z);}
virtual void RelRot(float x, float y, float z) {
__base->RelRot(x,y,z);}
virtual D3DXMATRIX GetMatrix() {return __base->GetMatrix();}
/************************************************** *****************************************/
public:
virtual void Render(LPDIRECT3DDEVICE9 device)
{__base->Render(device);}
virtual LPD3DXMESH GetMesh() { return ((Mesh*)__base)->GetMesh();}
private:
MobileEntity* __base;
/* Called by camera */
public:
virtual const D3DXMATRIX __GetTransform() const { return
__base->__GetTransform();}
virtual const D3DXMATRIX __GetRotate() const { return
__base->__GetRotate();};
virtual const D3DXMATRIX __GetScale() const { return
__base->__GetScale();};
/* Physics Addons */
public:
};
this way when if it was an active object originaly it would call the
active object function, which might modify data then call it's base...
I see now that this is probably not a good way to do this!! So thank
you very much I will go back and copy the base data, and treet physics
objects and active objects seperatly in the code in terms of you have
to maintain pointers to each individualy and they don't become a super
class combined!
Thank you.
Matt