【问题标题】:Error while passing abstract class pointer in derived class constructor在派生类构造函数中传递抽象类指针时出错
【发布时间】:2021-05-25 09:03:59
【问题描述】:

SoftwareDownload 是派生类。 从抽象类实现虚函数定义-da::skeleton::ServiceInterface_DMwithDASkeleton 请在下面找到代码。已编辑代码。 试图在派生类构造器中传递抽象类指针。

SoftwareDownloadpublic da::skeleton::ServiceInterface_DMwithDASkeleton { using DA_Skeleton= da::skeleton::ServiceInterface_DMwithDASkeleton;

protected:
    
da::skeleton::ServiceInterface_DMwithDASkeleton *DA_Skeleton_ptr;
   
public:

**SoftwareDownload**(da::skeleton::ServiceInterface_DMwithDASkeleton *DA_Skeleton_ptr ,ara::com::InstanceIdentifier instance_id ,ara::com::MethodCallProcessingMode mode);
  
  virtual ~**SoftwareDownload**();
 <ReturnType> **RequestToDownload**(const std::uint32_t& SID,const std::uint32_t& size)override;
 <ReturnType> **TransferData**(const std::uint32_t& SID,const std::uint32_t& Payload_Data)override;
  
}

//SoftwareDownload Constructor . Trying to initialise abstract class pointer.

**SoftwareDownload**::**SoftwareDownload**(da::skeleton::ServiceInterface_DMwithDASkeleton *DA_Skeleton_ptr ,ara::com::InstanceIdentifier instance_id ,ara::com::MethodCallProcessingMode mode)
   :**DA_Skeleton**(instance_id ,mode)
{
    //Initialize SoftwareDownload Skeleton for service instance 1

   **DA_Skeleton_ptr** = new DA_Skeleton(ara::com::InstanceIdentifier(1),ara::com::MethodCallProcessingMode::kEvent);
}

**SoftwareDownload**::~**SoftwareDownload**()=default;


//abstract Class

class **ServiceInterface_DMwithDASkeleton** : public da::ServiceInterface_DMwithDA, public ara::com::internal::skeleton::TypedServiceImplBase<ServiceInterface_DMwithDASkeleton> {

public:
**ServiceInterface_DMwithDASkeleton**(ara::com::InstanceIdentifier instance_id, ara::com::MethodCallProcessingMode mode = ara::com::MethodCallProcessingMode::kEvent) : ara::com::internal::skeleton::TypedServiceImplBase<ServiceInterface_DMwithDASkeleton>(instance_id, mode) {}

virtual ~**ServiceInterface_DMwithDASkeleton**() 
  { 
      //
  }
    
**virtual** <ReturnType> **RequestToDownload**(const std::uint32_t& SID,const std::uint32_t& size) = 0;
**virtual** <ReturnType> **TransferData**(const std::uint32_t& SID,const std::uint32_t& Payload_Data) = 0;
   
   

  

【问题讨论】:

  • 看起来您正在尝试实例化抽象类。da::skeleton::ServiceInterface_DMwithDASkeleton 某处。您包含的代码太少,我无法说出在哪里。请发帖minimal reproducible example
  • @TedLyngmo 。请查找完整代码。
  • 请发布真实代码。现在无法阅读或编译您在问题中提出的内容。创建minimal reproducible example
  • 我现在投票结束这个问题,因为你没有提供更多信息。

标签: c++ function class inheritance virtual


【解决方案1】:

ServiceInterface_DMwithDASkeleton 是一个抽象类。无法实例化。

然而,你正试图这样做:

using DA_Skeleton = da::skeleton::ServiceInterface_DMwithDASkeleton;

// ...

DA_Skeleton_ptr = new DA_Skeleton(...);

这就是您收到错误的原因。

【讨论】:

    猜你喜欢
    • 2021-07-15
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-04
    • 2020-10-16
    • 1970-01-01
    相关资源
    最近更新 更多