我正在使用Visual C++ 2010
,在Windows应用程序表单中:
#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 总是必须排在第一位......那么,我的前瞻声明是错误的吗?
由于您声明的是 Design 类型的变量(环境),因此此时编译器必须可以使用完整的类型。
通过对声明重新排序,您可以向编译器提供完整的类型。