错误C2143:语法错误:缺少'; '之前'^' [英] Error C2143: syntax error : missing '; ' before '^'
本文介绍了错误C2143:语法错误:缺少'; '之前'^'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下问题,我有一个A类,它有一个B类实例,B类有一个A类实例。在VisualStudio 2013中给我错误。
错误C2143:语法错误:缺少';'在'^'之前
以下是类代码。在此先感谢
我尝试过:
#includestdafx.h
#includeBAsterNode.h
using namespace System;
使用命名空间System :: Collections :: Generic;
ref class BAsterInfo
{
private:
IComparable ^ info;
BAsterNode ^ enlaceMayores; / *错误C2143 * /
public:
IComparable ^ GetInfo();
void SetInfo(IComparable ^);
BAsterNode ^ GetEnlaceMayores();
void SetEnlaceMayores(BAsterNode ^ enlaceMayoresP);
};
和其他班级
#includestdafx.h
#includeBAsterInfo.h
using namespace System;
使用命名空间System :: Collections :: Generic;
使用命名空间System :: Reflection;
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);
};
解决方案
Richard Mac Cutchan是对的,您已将两个标题包含在内,反之亦然错误。
我认为这是设计错误。所以你最好重新考虑C 2143发生的那一行。
另一个解决方案是所谓的前向声明。这意味着声明类名。 (我希望它在C ++中有效)
删除或评论包含!!!
// #includeBAsterNode.h
class BAsterNode; // 类的前向声明< /跨度>
I have the following problem, I have a class A that has an instance of a class B and class B has an instance of class A. In VisualStudio 2013 gives me the error.
error C2143: syntax error: missing ';' Before '^'
Below is the class code. Thanks in advance
What I have tried:
#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); };
and th other class
#include "stdafx.h" #include "BAsterInfo.h" using namespace System; using namespace System::Collections::Generic; using namespace System::Reflection; 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); };
解决方案
Richard Mac Cutchan is right, you have included both headers vice versa and that is mistake.
I would rate this as "design error". So you better rethink the line where the C 2143 occurs.
The other solution is a so called "forward declaration". It means to declare the class name. (I hope it works as in C++)
Remove or comment the include out !!!
//#include "BAsterNode.h
class BAsterNode; // forward declaration of the class
这篇关于错误C2143:语法错误:缺少'; '之前'^'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文