在没有继承的情况下实例化对象时出错

Error while instantiating an object without inheritance

到目前为止,我一直在使用从其他 classes 继承的 classes,现在我需要创建一个从任何东西继承的 class。我从我的客户 class 那里调用它,但我收到了对我来说没有意义的错误。我做错了什么?

数学帮助.h

public:
    float addPerc(float whole, float perc);
    float subPerc(float whole, float perc);

数学帮助.cpp

float addPerc(float whole, float perc)
{
    return 0;
}

float subPerc(float whole, float perc)
{
    return 0;
}
客户来电
MathHelp* mathHelp = new MathHelp();
float mathResult = mathHelp->addPerc(100,5);

错误:

error LNK2019: unresolved external symbol "public: float __thiscall MathHelp::addPerc(float,float)" (?addPerc@MathHelp@@QAEMMM@Z)
referenced in function "public: virtual void __thiscall EnergyManager::draw(class cocos2d::Renderer *,class cocos2d::Mat4 const &,unsigned int)" (?draw@EnergyManager@@UAEXPAVRenderer@cocos2d@@ABVMat4@3@I@Z)  

当您在 class 定义之外声明它们时,方法声明也需要具有 class 的名称。

float MathHelp::addPerc(float whole, float perc)
{
    return 0;
}

float MathHelp::subPerc(float whole, float perc)
{
    return 0;
}

使用已提供的代码,如果按照它们直接出现在文件中的方式使用它们,您将错过 class MathHelp 方法的范围,您会想尝试一些东西像这样:

float MathHelp::addPerc(float whole, float perc)
{
    return 0;
}

float MathHelp::subPerc(float whole, float perc)
{
    return 0;
}