C++ - 상속

C++ Class Inheritance

  • LocalDataBaseImpl
// FeatureHandlerBase.h
class FeatureHandlerBase
{
public:
  virtual void setFeatureGenericResponsible(FeatureGenericResponsible* featureResponsible) = 0;
}

//TackHandler.h
class TaskHandler: public FeatureHandlerBase
{
    // Parent Class : FeatureHandlerBase
    // Child Class : TaskHandler
  void setFeatureGenericResponsible(FeatureGenericResponsible* featureResponsible) override;
}

// TaskHandler.cc
void TaskHandler::setFeatureGenericResponsible(FeatureGenericResponsible* featureResponsible)
{
  m_featureResponsible = featureResponsible; // featureResponsible will be set as TaskHandler
  m_LocalDataData = m_featureResponsible->getData();
}

// LocalDataBaseImpl.h
class LocalDataBaseImpl: public LocalData,
                         public FeatureGenericResponsible,
{
    // Parent Class : LocalData, FeatureGenericResponsible
    // Child Class : LocalDataBaseImpl
}

// LocalDataBaseImpl.cc
void LocalDataBaseImpl::initFeatureHandler(void)
{
  FeatureHandlerBase* taskHandler = new TaskHandler(); // create TaskHandler object
  taskHandler->setFeatureGenericResponsible(static_cast<FeatureGenericResponsible*>(this)); // this : TaskHandler object
  m_featureHandlerMap.insert(std::pair<FeatureTypeE, FeatureHandlerBase*>(FEAT_TYPE_AAA, taskHandler));
}

virtual function

  • A virtual function allows derived classes to replace the implementation provided by the base class.

static_case(obj)

Change Object type

this

  • The this pointer holds the address of current object

Categories:

Updated: