2017-08-18 56 views
-2

發現每次我跑我的Qt程序,它提供了以下錯誤:Findfactorial並沒有在此範圍內

Findfactorial was not found in this scope

可能有人建議,爲什麼?我具備的功能在我mainwindow.cpp

int findFactorial(int x){ 
    if(x == 1){ 
     return 1; 
    } else { 
     return x*findFactorial(x-1); 
    } 
} 

mainwindow.h

class MainWindow : public QMainWindow 
{ 
    Q_OBJECT 

public: 
    explicit MainWindow(QWidget *parent = 0); 
    bool ok = false; 
    int findFactorial(int x); 
    ~MainWindow(); 

private slots: 

    void on_clear_button_clicked(); 

    void on_sqr_button_clicked(); 

    void on_exp_two_button_clicked(); 

    void on_pi_button_clicked(); 

    void on_ceil_button_clicked(); 

    void on_factorial_button_clicked(); 

private: 
    Ui::MainWindow *ui; 
}; 
+0

您可能在某處寫了'Findfactorial',但函數名爲'findFactorial'(C++區分大小寫)。 –

回答

2

你必須明確地說,其範圍/命名空間,這種功能使用所屬範圍分辨率操作

int MainWindow::findFactorial(int x){ 
    if(x == 1){ 
     return 1; 
    } else { 
     return x*findFactorial(x-1); 
    } 
} 
+0

謝謝你不知道:) –

+0

很高興幫助:-)你可以閱讀更多關於命名空間[這裏(點擊)](http://en.cppreference.com/w/cpp/language/namespace)。 –