我在尝试在类中创建对象时面临如何解决链接错误

I am facing while trying to create an object inside the class, How to resolve linking error?

本文关键字:何解决 解决 错误 链接 创建对象      更新时间:2023-10-16

示例代码:

ABC.h

Class ABC{
    public:
    ABC();
    virtual bool a();
    virtual bool b();
    virtual bool c();
    protected: 
        ~ABC();
    private:
    BaseLM* m_lm;
    }

abc.cpp

ABC::ABC()
{
#ifndef KASH
    m_lm(new BaseLMD());
#else
    m_lm(new BaseLMI());
#endif 
}

我已经从BaseLM BaseLMDBaseLMI派生类,并尝试在abc.cpp中创建对象收到错误:

错误 C2064:术语的计算结果不等于采用 1 个参数的函数

我希望根据类内部# define ifndef KASH创建对象abc.cpp请提出相同的解决方案。

我想你想使用初始值设定项列表。

ABC::ABC()
:
#ifndef KASH
    m_lm(new BaseLMD())
#else
    m_lm(new BaseLMI())
#endif
{
}