c++ 之 ‘using element_type = {aka ‘class *’’} has no member named ‘InitLog’; did you mean ‘Init’?

在C++项目开发中,遇到一个编译错误提示类BluetoothTransparentModule没有成员InitLog。实际上,编译器已经给出提示可能是想调用Init。问题在于InitLog未在类中定义。解决方案是添加InitLog成员并实现它。修复后,代码能够正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

慢慢习惯c++...

最近在弄一个项目,用c++开发。刚才碰到这个报错,由于是复制同事的代码,一事不知所措。

‘using element_type = class modules_bluetoothtransparent::BluetoothTransparentModule’ {aka ‘class modules_bluetoothtransparent::BluetoothTransparentModule’} has no member named ‘InitLog’; did you mean ‘Init’?
     pobjBluetoothTransparentModuleule->InitLog();

排查发现,是InitLog在类中没有定义。

仔细看编译其实已经给了提示,没有成员名称。还给出了提示 Init 。

bool BluetoothTransparentModInitializer::InitModule(
                        module_management::ModuleResource *pobjModResource,
                        std::shared_ptr<module_management::BaseModule> pobjModule)  {
    if (NULL == pobjModResource || nullptr == pobjModule) {
        ac_("cloudlog init failed, input pointer null");
        return false;
    }

    std::shared_ptr<BluetoothTransparentModule> pobjBluetoothTransparentModuleule =
                    std::dynamic_pointer_cast<BluetoothTransparentModule>(pobjModule);
    if (nullptr == pobjBluetoothTransparentModuleule) {
        ac_("module %s init failed, cast error", pobjModule->GetModuleName().c_str());
        ac_("BluetoothTransparentModule typeid: {}", typeid(BluetoothTransparentModule).name());
        ac_("*pobjModule typeid: {}", typeid(*pobjModule).name());
        return false;
    }

    pobjBluetoothTransparentModuleule->Init();
    pobjBluetoothTransparentModuleule->InitLog();
   ac_("module %s inited", pobjBluetoothTransparentModuleule->GetModuleName().c_str());

    return true;
}

class BluetoothTransparentModule : public BaseModule {
 public:
    virtual ~BluetoothTransparentModule() {}

    bool Init(void) override;
    bool Uninit(void) override;

    virtual bool SetCommModule(std::shared_ptr<modules_comm::CommModule> spComm);
};

解决:把InitLog成员加上并实现即可。

class BluetoothTransparentModule : public BaseModule {
 public:
    virtual ~BluetoothTransparentModule() {}

    bool Init(void) override;
    bool Uninit(void) override;
    virtual int32_t InitLog(void);

    virtual bool SetCommModule(std::shared_ptr<CommModule> spComm);
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值