Jump to content
  • Advertisement
Sign in to follow this  
hplus0603

[.net] Returning a ref struct in C++/CLR

This topic is 3262 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here's some code:
namespace fluff
{
	public ref struct Vector3
	{
	  float X;
	  float Y;
	  float Z;
	  Vector3(float x, float y, float z)
	  {
	    X = x;
	    Y = y;
	    Z = z;
	  }
	  Vector3 operator+(Vector3 b)
	  {
	    Vector3 ret(X + b.X, Y + b.Y, Z + b.Z);
	    return ret;
	  }
	};
}
I get error C2440 on the operator+ line, saying I can't convert a Vector3 to a Vector3 ... So, how do I return instance of value types?

Share this post


Link to post
Share on other sites
Advertisement
Just to explain further, for ref types you have to move them around -- returns mainly -- using handles (Vector3^). In your case, the parameter would have actually been Vector3^ and gained stack semantics, which is an entirely new form of crazy.

Oh and honestly, you're much better off simply taking the SlimDX code for this stuff (MIT license). We've done all the stupid legwork, please don't be shy in leveraging it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!