Class 对另一个类文件中方法的未定义引用,如何修复?

Class 对另一个类文件中方法的未定义引用,如何修复?,class,undefined,Class,Undefined,我一直在做一个程序,它会做一些关于音频、SPL等的等式 我决定让主类文件向用户提供一个选项,让用户选择他想要做的方程,而这些方程保存在另一个类文件中 Atm,主类文件的设置只是为了测试maxpakspl,但我无法让它运行 main.cpp //Kh[a]os #include "equations.h" #include <iostream> void mainLoop(); int maxSPL = 0; int main() { std::cout << "Cr

我一直在做一个程序,它会做一些关于音频、SPL等的等式

我决定让主类文件向用户提供一个选项,让用户选择他想要做的方程,而这些方程保存在另一个类文件中

Atm,主类文件的设置只是为了测试maxpakspl,但我无法让它运行

main.cpp

//Kh[a]os
#include "equations.h"
#include <iostream>

void mainLoop();

int maxSPL = 0;

int main()
{
std::cout << "Created by Kh[a]os" << std::endl << std::endl;
mainLoop();

return 0;
}

void mainLoop()
{

std::cout << "hi";
maxSPL = equations::maxPeakSPL();
std::cout << std::endl << maxSPL << "db" << std::endl << std::endl;


    }
方程式h

#ifndef EQUATIONS_H
#define EQUATIONS_H

#include <string>


class equations
{
    public:
        equations();
        static int maxPeakSPL();
    protected:
    private:
};

#endif // EQUATIONS_H
方程组

#include "equations.h"
#include <iostream>
#include <string>

equations::equations()
{

}

static int maxPeakSPL()
{

    int Sens = 0;
    double Distance = 0;
    int Watts = 0;
    int sWatts = 2;
    int eWatts = 0;
    double maxSPL = 0;
    double counter = 0;
    double wall = 0;
    std::string corner = "";

bool v = true;

    std::cout << "Sensitivity (db): " << std::endl;
    std::cin >> Sens;
    std::cout << "Amplification (watts): " << std::endl;
    std::cin >> Watts;
    std::cout << "Listening Distance (meters): " << std::endl;
    std::cin >> Distance;
    std::cout << "Distance from Wall (ft): " << std::endl;
    std::cin >> wall;
    std::cout << "Are you they in a corner? (y/n): " << std::endl;
    std::cin >> corner;


    maxSPL = Sens - (Distance*3 - 3);


while(v == true)
{
if (sWatts > Watts)
        {
            v = false;
            eWatts = sWatts;
            sWatts = sWatts/2;
            Watts = Watts-sWatts;
            counter = (double)Watts/(double)eWatts;
            counter = counter*3;
            maxSPL = maxSPL + counter;

        }

     if (v == true)
     {
        maxSPL = maxSPL + 3;
        sWatts = sWatts*2;
     }

    }
    if (wall <= 4)
    maxSPL = maxSPL + 3;

    if (corner == "Y" || corner == "YES" || corner == "y" || corner == "yes")
    maxSPL = maxSPL + 3;

    return maxSPL;

}
运行它时遇到的错误是:未定义对“equations::maxPeakSPL”的引用


我不知道如何解决这个问题,任何帮助都会很好。谢谢。

在main中,尝试将函数放在主块之前。在指令/标志的名称前加一个下划线。

很抱歉,因为我有点新手,所以我不太明白应该更改什么。你是说:void mainLoop;int方程组::maxpakspl;不,我的意思是,如果你有你的空主环的主体,你需要把它放在你的int main之前,因为C++是自顶向下的。被宣布为最高层?mainLoop运行良好,一切正常,只是一行从其他类错误调用函数。您要做的是使用函数模板,但是在C++中,int main需要使用最后一个代码块来使用同一个文件中创建的函数。我不完全确定这是否是您未定义引用的原因,因为我很久没有使用C++了。