首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未定义对另一个类文件中方法的引用,如何修复?

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

Stack Overflow用户
提问于 2012-04-22 06:41:43
回答 1查看 122关注 0票数 0

我一直在做一个程序,它将做一些关于音频,SPL等的方程。

我决定让主类文件为用户提供一个选项来选择他想要做的方程式,而方程式则保存在另一个类文件中。

主类文件只是为了测试maxPeakSPL()而设置的,但是我不能让它运行。

main.cpp

代码语言:javascript
复制
//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;


    }

equations.h

代码语言:javascript
复制
#ifndef EQUATIONS_H
#define EQUATIONS_H

#include <string>


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

#endif // EQUATIONS_H

equations.cpp

代码语言:javascript
复制
#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;

}

当我运行它时,我得到的错误是:未定义对‘error::maxPeakSPL()’的引用。

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-22 06:59:51

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10263666

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档