creating an array of a managed class.

.NET question (is this the right forum?)

Page 1 of 1

3 Replies - 1759 Views - Last Post: 05 February 2009 - 09:57 AM

#1 TheMagnitude  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 144
  • Joined: 12-January 08

creating an array of a managed class.

Post icon  Posted 03 February 2009 - 01:53 PM

I've just started learning Visual C++ 2008 and I am porting my Calculator over to use .NET.

So I've had to change the instances of std::string with there System::String^ equivilants.

I've been working on this calculator for about 3 hours browsing the internet and finally I've got down the error count from 80 to 1, the only error is:

error C3145: 'operators' : global or static variable may not have managed type 'cli::array<Type> ^'
		with
		[
			Type=operate ^
		]
		may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap


I've tried a few different things but none of them work.

Here is the class and code structure for that section of my program.

// OPERATOR CLASS
ref class operate
{
	public:
		array<bool>^ param;
		String^ name;
};

// ADD AN OPERATOR
operate^ addOp(String^ a, bool b, bool c)
{
	operate^ temp;
	//temp->param = gcnew array<bool>(2); // not sure whether this is needed
	temp->name = a;
	temp->param[0] = b;
	temp->param[1] = c;
	opNumber ++;
	return temp;
}

// OPERATOR LIST
array<operate^>^ operators = // this is the line the error is on
{
	addOp("PI"		,false, false),
	addOp("E"		 ,false, false),
	addOp("X"		 ,false, false),
	addOp("Y"		 ,false, false),
	addOp("Z"		 ,false, false),
	addOp("ANS"	   ,false, false),
	addOp("acosh"	 ,false, true),
	addOp("asinh"	 ,false, true),
	addOp("atanh"	 ,false, true),
	addOp("cosh"	  ,false, true),
	addOp("sinh"	  ,false, true),
	addOp("tanh"	  ,false, true),
	addOp("acos"	  ,false, true),
	addOp("asin"	  ,false, true),
	addOp("atan"	  ,false, true),
	addOp("cos"	   ,false, true),
	addOp("sin"	   ,false, true),
	addOp("tan"	   ,false, true),
	addOp("log"	   ,false, true),
	addOp("ln"		,false, true),
	addOp("!"		 ,true, false),
	addOp("%"		 ,true, true),
	addOp("^"		 ,true, true),
	addOp("/"		 ,true, true),
	addOp("*"		 ,true, true),
	addOp("+"		 ,true, true)
};

This post has been edited by TheMagnitude: 03 February 2009 - 01:56 PM


Is This A Good Question/Topic? 0
  • +

Replies To: creating an array of a managed class.

#2 TheMagnitude  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 144
  • Joined: 12-January 08

Re: creating an array of a managed class.

Posted 04 February 2009 - 04:00 PM

I figured it out on my own after all.

The solution was that array<operate^>^ operators was being defined globally, as soon as I defined it locally it worked :).

Also if I have any more questions regarding Visual C++ 2008 where should I post them to get more replies?
Was This Post Helpful? 0
  • +
  • -

#3 TheMagnitude  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 144
  • Joined: 12-January 08

Re: creating an array of a managed class.

Posted 05 February 2009 - 08:59 AM

Is there a reason no one is posting, if so please tell me.
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6092
  • View blog
  • Posts: 23,612
  • Joined: 23-August 08

Re: creating an array of a managed class.

Posted 05 February 2009 - 09:57 AM

My best guess as the the lack of responses would be that most people in the .NET space avoid Managed C++ and stick to C# or VB.NET. I know I do.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1