Hello all . I have just started using the gcnew instead of new for the public ref class, that i have needed to learn for windows forms. I have a problem that shouldn't be as difficult as it is.

I have a class that i made called vector2 . It is a vector with with slots in the method. It looks like this.

public ref class  vector2{
	
	public:

	System::String ^x;
	System::String ^y;

	System::Windows::Forms::PictureBox ^PictureBox;

	void Position(System::String ^ X, System::String^ Y){


	x=X;

	y=Y;
	
	
	};
	
	
	};

I do this to set the X Y values of the Position()

Object reference not set to an instance of an object.
use the new keyword to create and instance object.

vector2 ^v1;
	v1->Position(posx,posy);
       
	//v1= gcnew vector2();


		
	this->textBox2->Text=""+v1->x;

Neither of these work. my program stops and i get this warning/ error

Object reference not set to an instance of an object.
use the new keyword to create and instance object.

This would work for sure as just a regular class with regular strings and all. Its frustrating, please help thanks.

...so (even though you solved your own question)...
Was this the answer?:

vector2^ v1 = gcnew vector2();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.