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();
This question has already been answered. Start a new discussion instead.