سؤال

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?

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top