2016-11-26 48 views
-2

我重新安排了一些代碼,現在我得到以下錯誤:c + +建立自己的錯誤:類沒有指定類型

g++ main.cpp myframe.cpp `wx-config --cxxflags --libs std` -o main 
myframe.cpp:5:1: error: ‘Myframe’ does not name a type 

我敢肯定的錯誤與夾雜物,而不是錯誤的代碼

下面是源文件(相關部分只):

main.cpp中:

#include "main.h" 
#include "myframe.h" 

IMPLEMENT_APP(MyApp) 

bool MyApp::OnInit(){ 
    Myframe *menu = new Myframe(wxT("Application")); 
    menu->Show(true); 
    return true; 
}; 

main.h:

#include <wx/wx.h> 

class MyApp : public wxApp 
{ 
    public: 
    virtual bool OnInit(); 
}; 

myframe.cpp:

#include "main.h" 

Myframe::Myframe(const wxString& title) 
///^ERROR 
     : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(300, 300)) 
{ 
    ... 
} 

myframe.h:

#include <wx/wx.h> 
#include <wx/menu.h> 

class Myframe : public wxFrame 
{ 
public: 
    Myframe(const wxString& title); 

    ... 
}; 

...(function definitions,event table and enums) 
+3

您需要在'myframe.cpp'中包含'#include「myframe.h」'。 – songyuanyao

+0

@songyuanyao。這將導致Myframe的多重定義,因爲它已經包含在main.cpp中了... – westernCiv

+0

您不應該將函數定義放在'myframe.h'中,將它們全部移到'myframe.cpp'。頭文件的聲明,實現文件的定義。 – songyuanyao

回答

1

您可以添加到#include <myframe.h> 「myframe.cpp」 文件。 ,因爲在「myframe.cpp」文件中沒有定義Myframe。