Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);
};
Posted
Updated 18-Apr-17 5:08am
v2
Comments
Ravi Bhavnani 13-Apr-17 13:49pm    
Are confusing Pascal syntax with C/C++? Did you mean to use * or do you really mean to use a handle reference?

/ravi
[no name] 13-Apr-17 15:46pm    
Looks like C++/CLI so the ^ would be correct.
Ravi Bhavnani 13-Apr-17 16:31pm    
Yep, that's what I meant by the handle reference.

/ravi
Richard MacCutchan 14-Apr-17 4:43am    
BasterInfo includes BasterNode, and BasterNode includes BasterInfo; that may confuse the compiler.

1 solution

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 !!!
C++
//#include "BAsterNode.h
C++
class BAsterNode; // forward declaration of the class
 
Share this answer
 
Comments
Philippe Mori 18-Apr-17 18:47pm    
Well, as it is obviously managed class, the forward declaration also need the ref modifier.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900