gpt4 book ai didi

C++ Windows 应用程序窗体无法进行转发声明

转载 作者:太空宇宙 更新时间:2023-11-04 13:57:39 25 4
gpt4 key购买 nike

我在 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' uses undefined class 'MyProgram::Design'

如果我切换定义顺序,编译时不会出错,但在 Windows 应用程序窗体中,类 Form1 始终必须在第一位...那么,我的前向声明是否错误?

最佳答案

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

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

关于C++ Windows 应用程序窗体无法进行转发声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20747514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com