C++ C++;生成错误:类未命名类型
我重新整理了一些代码,现在出现以下错误:C++ C++;生成错误:类未命名类型,c++,class,build,compiler-errors,include,C++,Class,Build,Compiler Errors,Include,我重新整理了一些代码,现在出现以下错误: 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(MyA
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;
};
主要条款h:
#include <wx/wx.h>
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
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)
#包括
#包括
类Myframe:publicwxframe
{
公众:
Myframe(constwxstring和title);
...
};
…(函数定义、事件表和枚举)
您可以将#include
添加到“myframe.cpp”文件中。
因为“Myframe.cpp”文件中没有Myframe的定义。您需要
#在Myframe.cpp
中包含“Myframe.h”
@songyuanyao。这将导致Myframe的多个定义,因为它已经包含在main.cpp中…您不应该将函数定义放在Myframe.h
中,将它们全部移动到Myframe.cpp
。头文件的声明,实现文件的定义。@westernCiv使用包括保护。只要查找头文件和实现文件的任何例子。@ WestNCIV:用第三方框架编写GUI应用程序并不是开始学习C++的最佳方式。在标题中包含卫士是该语言的一个非常基本的概念,在处理如此复杂的主题之前必须完全理解。
#include <wx/wx.h>
#include <wx/menu.h>
class Myframe : public wxFrame
{
public:
Myframe(const wxString& title);
...
};
...(function definitions,event table and enums)