Sunday, June 19, 2016

Reference_&_Pointer

Q?
-----------------
-------------------------------------------------
//FILE##Component.h
#include "Transform"
class Component
{
// implementation with reference
public:
Component(Transform& transform):_transform(transform){}
Transform& GetRefTransform(){return _transform;}
private:
Transform _transform;
// implementation with pointer
public:
Component(Transform* transform):_ptransform(transform){}
Transform* GetPtrTransform(){return _ptransform;}
private:
Transform * _ptransform;
}

//FILE##Camera.h
class Camera : public Component
{
public:
Camera(Transform& transform):Component(transform){}
public:
Camera(Transform* ptransform):Component(ptransform){}
}

//FILE##FreeCamera.h
class FreeCamera: public Component
{
public:
FreeCamera(Transform& transform):Component(transform){}
public:
FreeCamera(Transform* ptransform):Component(ptransform){}
}

//FILE##main.cpp
{// why failed to use the same attribtue _transform inherited from the base_class in this way????
Transform transform;
transform.GetPosition().SetPosition(Vector3(x,y,z));
Camera* mainCamera = new Camera(transform);
// some operation about mainCamera
FreeCamera* freeCamera = new FreeCamera(transform);
}
{// while this is okay..
Transform * ptransform = new ptransform();
ptransform->GetPosition().SetPosition(Vector3(x,y,z));
Camera * pMaincamera = new Camera(ptransform);
// operations on pMaincamera
FreeCamera * pFreeCamera = new FreeCamera(ptransform);
}


--------------------------------

No comments:

Post a Comment