C++ cli 错误C2143:语法错误:缺少'';在'之前^';

C++ cli 错误C2143:语法错误:缺少'';在'之前^';,c++-cli,C++ Cli,我有以下问题,我有一个类a有一个类B的实例,而类B有一个类a的实例。在VisualStudio 2013中,我遇到了错误“错误C2143:语法错误:缺少“;”下面的“^”之前是类代码。提前谢谢 #include "stdafx.h" #include "BAsterNode.h" using namespace System; using namespace System::Collections::Generic; ref class BAsterInfo { private: I

我有以下问题,我有一个类a有一个类B的实例,而类B有一个类a的实例。在VisualStudio 2013中,我遇到了错误“错误C2143:语法错误:缺少“;”下面的“^”之前是类代码。提前谢谢

#include "stdafx.h"
#include "BAsterNode.h"

using namespace System;
using namespace System::Collections::Generic;

ref class BAsterInfo
{
private:
    IComparable^ info;
    BAsterNode^ enlaceMayores; /* error C2143 */
public:
    IComparable^ GetInfo();
    void SetInfo(IComparable^);
    BAsterNode^ GetEnlaceMayores();
    void SetEnlaceMayores(BAsterNode^ enlaceMayoresP);
};
第二节课

#include "stdafx.h"
#include "BAsterInfo.h"

using namespace System;
using namespace System::Collections::Generic;

ref class BAsterNode
{
private:
    BAsterNode^ enlaceMenores;
    List<BAsterInfo^>^ listaInformacion;
        int Find(BAsterInfo^ info);
public:
    List<BAsterInfo^>^ GetListaInfo();
    void SetListaInfo(List<BAsterInfo^>^ listaInfoP);
    BAsterNode^ GetEnlaceMenores();
    void SetEnlaceMenores(BAsterNode^ enlaceMenoresP);
};
#包括“stdafx.h”
#包括“BAsterInfo.h”
使用名称空间系统;
使用命名空间System::Collections::Generic;
参考类BAsterNode
{
私人:
BAsterNode ^ enlaceMenores;
列表^列表格式;
int Find(BAsterInfo^info);
公众:
列表^GetListaInfo();
作废SetListaInfo(列表^listaInfoP);
BAsterNode ^GetEnlaceMenores();
void SetEnlaceMenores(BAsterNode^enlaceMenoresP);
};

> p> C++ +CLI,类似C++,使用单遍编译。由于两个头文件都包含彼此,预处理器最终会将其中一个放在第一位,而该头文件最终会出现一个错误,其中第二个类尚未定义。我确信您也会收到一条关于未定义类的错误消息

要解决此问题,请不要包含另一个头文件中的一个头文件。包括.cpp文件中的两个头文件,并在每个头文件中使用另一个类的转发声明。这将允许您在各种方法声明中使用另一个类。您需要包含在.cpp中的头文件来调用其他类上的任何方法,因此,如果您有任何函数使用头文件中定义的其他类,则需要将它们移动到.cpp

#include "stdafx.h"

using namespace System;
using namespace System::Collections::Generic;

// Forward declaration
ref class BAsterInfo;

ref class BAsterNode
{
private:
    BAsterNode^ enlaceMenores;
    List<BAsterInfo^>^ listaInformacion;
        int Find(BAsterInfo^ info);
public:
    List<BAsterInfo^>^ GetListaInfo();
    void SetListaInfo(List<BAsterInfo^>^ listaInfoP);
    BAsterNode^ GetEnlaceMenores();
    void SetEnlaceMenores(BAsterNode^ enlaceMenoresP);
};
#包括“stdafx.h”
使用名称空间系统;
使用命名空间System::Collections::Generic;
//远期申报
参考类BAsterInfo;
参考类BAsterNode
{
私人:
BAsterNode ^ enlaceMenores;
列表^列表格式;
int Find(BAsterInfo^info);
公众:
列表^GetListaInfo();
作废SetListaInfo(列表^listaInfoP);
BAsterNode ^GetEnlaceMenores();
void SetEnlaceMenores(BAsterNode^enlaceMenoresP);
};

> p> C++ +CLI,类似C++,使用单遍编译。由于两个头文件都包含彼此,预处理器最终会将其中一个放在第一位,而该头文件最终会出现一个错误,其中第二个类尚未定义。我确信您也会收到一条关于未定义类的错误消息

要解决此问题,请不要包含另一个头文件中的一个头文件。包括.cpp文件中的两个头文件,并在每个头文件中使用另一个类的转发声明。这将允许您在各种方法声明中使用另一个类。您需要包含在.cpp中的头文件来调用其他类上的任何方法,因此,如果您有任何函数使用头文件中定义的其他类,则需要将它们移动到.cpp

#include "stdafx.h"

using namespace System;
using namespace System::Collections::Generic;

// Forward declaration
ref class BAsterInfo;

ref class BAsterNode
{
private:
    BAsterNode^ enlaceMenores;
    List<BAsterInfo^>^ listaInformacion;
        int Find(BAsterInfo^ info);
public:
    List<BAsterInfo^>^ GetListaInfo();
    void SetListaInfo(List<BAsterInfo^>^ listaInfoP);
    BAsterNode^ GetEnlaceMenores();
    void SetEnlaceMenores(BAsterNode^ enlaceMenoresP);
};
#包括“stdafx.h”
使用名称空间系统;
使用命名空间System::Collections::Generic;
//远期申报
参考类BAsterInfo;
参考类BAsterNode
{
私人:
BAsterNode ^ enlaceMenores;
列表^列表格式;
int Find(BAsterInfo^info);
公众:
List ^GetListaInfo();
作废SetListaInfo(列表^listaInfoP);
BAsterNode ^GetEnlaceMenores();
void SetEnlaceMenores(BAsterNode^enlaceMenoresP);
};