C ++ Windows应用程序表单无法进行前向声明

时间:2013-12-23 16:36:53

标签: c++ forms class declare

我在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类始终必须是第一个...那么,我的前向声明是错误的吗?

1 个答案:

答案 0 :(得分:0)

由于您声明了一个类型为Design的变量(Environment),因此当时编译器必须可以使用完整类型。

通过重新排序声明,您将向编译器提供完整的类型。