2012-04-21 12 views
0

私は、オーディオ、SPLなどに関する2つの方程式を実行するプログラムに取り組んできました。別のクラスファイルのメソッドへの未定義のリファレンス、修正方法?

私はメインクラスファイルに、彼が望む方程式を選択するオプションを提示することにしました方程式は別のクラスファイルに格納されています。

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

あなたのメインでは、メインブロックの前に機能を入れてみてください。ディレクティブ/フラグの名前の前にアンダースコアを含めます。

+0

私はお詫び申し上げますが、私は少し初心者であるため、私は何を変えなければならないかをよく理解していない。あなたは言っていますか: void mainLoop(); int式:: maxPeakSPL(); –

+0

いいえ、私はあなたのvoid mainloop()の本体を持っていることを意味しています、あなたはint main()の前に置く必要があります。なぜならC++はトップダウンだからです。 – Nightvein

+0

はvoid mainLoop()の目的ではありません。トップで宣言されていますか? mainLoopは正常に動作し、すべてが実行され、他のクラスのエラーから関数を呼び出すその1行だけが実行されます。 –

関連する問題