我在Windows应用程序表单中使用Visual C++ 2010 :
#pragma once namespace MyProgram { using namespace System; using namespace System::IO; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; ref class Design; //Forward Declariong of Class Design /// <summary> /// Summary for Form1 /// </summary> public ref class Form1 : public System::Windows::Forms::Form { private: Design Enviroment; //Declaring object of class: Design public: Form1(void) { InitializeComponent(); // //TODO: Add the constructor code here // } }; public ref class Design { private: String^ Color; public: Design() { //TODO: Add the Constructor code here } };我得到error: MyProgram::Form1::Enviroment'使用未定义的类' MyProgram::Design '
如果我切换定义顺序,它将编译没有错误,但在Windows应用程序窗体中,类Form1总是必须首先...那么,我的前向声明是错误的吗?
I am using Visual C++ 2010, in Windows Application Form:
#pragma once namespace MyProgram { using namespace System; using namespace System::IO; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; ref class Design; //Forward Declariong of Class Design /// <summary> /// Summary for Form1 /// </summary> public ref class Form1 : public System::Windows::Forms::Form { private: Design Enviroment; //Declaring object of class: Design public: Form1(void) { InitializeComponent(); // //TODO: Add the constructor code here // } }; public ref class Design { private: String^ Color; public: Design() { //TODO: Add the Constructor code here } };And i get the error: MyProgram::Form1::Enviroment' uses undefined class 'MyProgram::Design'
If I switch the definition order, it will compile with no errors, but in windows application form the class Form1 always has to be first... So, is my forward declaration wrong?
最满意答案
由于您声明了一个类型为Design的变量(Environment),因此当时编译器必须可以使用完整类型。
通过重新排序声明,您将向编译器提供完整类型。
Since you are declaring a variable (Environment) of type Design the complete type has to be available to the compiler at that time.
By re-ordering your declarations, you are providing the complete type to the compiler.
更多推荐
发布评论