新手疑问,为什么这个类编译时显示成员函数重复定义
这个类能够编译通过。
#ifndef MYMAINWINDOW_H#define MYMAINWINDOW_H#include <QMainWindow>#include <QAction>class MyMainWindow : public QMainWindow{ Q_OBJECTpublic: MyMainWindow(){createActions();}private: void createActions(){newAction = new QAction(tr("&New"), this);} QAction *newAction;};#endif // MAINWINDOW_H#ifndef MYMAINWINDOW_H#define MYMAINWINDOW_H#include <QMainWindow>#include <QAction>class MyMainWindow : public QMainWindow{ Q_OBJECTpublic: MyMainWindow();private: void createActions(); QAction *newAction;};MyMainWindow::MyMainWindow(){ createActions();}void MyMainWindow::createActions(){ newAction = new QAction(tr("&New"), this);}#endif // MAINWINDOW_H