2012-04-21 31 views
0

我一直在做一個程序,將就音頻,SPL等方面做幾個方程。未定義的引用另一個類文件中的方法,如何解決?

我決定讓主要的類文件給用戶提供一個選項來選擇他想要的方程要做,而這些方程式則放在另一個類文件中。

Atm,主要的類文件被設置爲測試maxPeakSPL(),但我無法讓它運行。

的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; 


    } 

equations.h

#ifndef EQUATIONS_H 
#define EQUATIONS_H 

#include <string> 


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

#endif // EQUATIONS_H 

equations.cpp

#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; 

} 

我得到的錯誤,當我運行它是:未定義的引用`方程: :maxPeakSPL()'

I沒有線索如何解決這個問題,任何援助將是偉大的。謝謝。

回答

0

在你的main中,試着把這個函數放在main塊之前。在指令/標誌的名稱前加上下劃線。

+0

我很抱歉,但因爲我有點新手,我不太瞭解我應該改變什麼。你是說: void mainLoop(); int equations :: maxPeakSPL(); – 2012-04-21 23:08:49

+0

不,我的意思是你有void mainloop()的主體,你需要把它放在你的int main()之前,因爲C++是自頂向下的。 – Nightvein 2012-04-21 23:11:35

+0

不是void mainLoop()的目的;被宣佈在頂部? mainLoop運行正常,一切運行,只是一行從其他類錯誤調用函數。 – 2012-04-21 23:13:48

相關問題