不允许成员函数重新声明

chu*_*Dub 1 c++ compiler-errors

如果我在mainwindow.cpp中定义函数,该函数可以工作,但是当我在radiobuttons.cpp中定义它并尝试从mainwindow.cpp调用它时,项目将无法编译.

mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H        
    #include <QMainWindow>

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
        Q_OBJECT

        public:
            explicit MainWindow(QWidget *parent = 0);

            void build_radios();  //this function

            ~MainWindow();

    };    
#endif // MAINWINDOW_H
Run Code Online (Sandbox Code Playgroud)

radiobuttons.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

    void MainWindow::build_radios()
     {  

    //... some code

     }
Run Code Online (Sandbox Code Playgroud)

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

void MainWindow::radio_buttons();   //error: C2761: 'void MainWindow::build_radios(void)' : member function redeclaration not allowed

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)

{

radio_buttons();

}
Run Code Online (Sandbox Code Playgroud)

Luc*_*ore 5

这不是定义,编译器将其视为类定义之外的成员函数的声明,这是非法的.只需删除该行.它不应该在那里,它没有用处.

实际上,将实际定义从一radiobuttons.cpp开始移动到mainwindow.cpp一致性.为什么MainWindow在不同的实现文件中声明成员?