Managed/Unmanaged Problem... Help!

Started by
1 comment, last by Raeldor 17 years, 6 months ago
Hi All, I am trying to wrap my C++ classes in Managed C++ so I can call them from C#, which works great for regular parameters (int, float), but when I define...

	public ref class Vector3
	{
	public:
		Vector3(float in_x, float in_y, float in_z) {x=in_x; y=in_y; z=in_z;}

		float x, y, z;
	};

	public ref class MCamera
	{
	private:
	public:
		MCamera(Vector3 in_source) {}
	};

and then try and call this from C# with...

            m_camera = new MCamera(new Vector3(0.0f, 0.0f, 0.0f));

I get the compile error... D:\Documents and Settings\rprice\My Documents\Visual Studio 2005\Projects\Terraformer4\Terraformer4\Form1.cs(40,24): error CS1501: No overload for method 'MCamera' takes '1' arguments The c++ assembly compiles find and the constructor looks good in the object browser for the assembly. Why is C# not recognizing this as having parameters? The following works fine in C# too...

            Vector3 test = new Vector3(0.0f, 0.0f, 0.0f);
            test.x = 1.0f;

I am really confused... help! Thanks Rael
Advertisement
im not sure cause i havnt used managed c++ before but i think this
public ref class MCamera{private:public:    MCamera(Vector3 in_source) {}};

should be this
public ref class MCamera{private:public:    MCamera(Vector3^ in_source) {}};

so the compiler can distinguish passing a Vector3 (what ur code said) and a managed pointer to a Vector3 (what u do in the c# code).

Hope that helps
That did the trick! Thanks very much... still trying to get the hang of this managed c++ thing! :D

This topic is closed to new replies.

Advertisement