own Vector class

G

Guest

the class:

public __gc class Vector {

private:
Double y, x, z;

public:
Vector() {
y(0),
x(0),
z(0)
{
}
};

Vektor(Double y, Double x, Double z){
y = x1;
x = x2;
z = x3;
}
Vector(String __gc* strVector); // "123.23,1232.23,4235345."

__property Double get_Y();
__property void set_Y(Double a);
__property Double get_X();
__property void set_X(Double b);
__property Double get_Z();
__property void set_Z(Double c);
};

Now i have another method which tries to return a vector:
class...
static Vektor* get_Vektor(String* e, String* p){

return new
Vektor(Convert::ToDouble(kind),Convert::ToDouble(domain),Convert::ToDouble(category));
}
...
end class


Vektor* obj = new Vektor();
obj = Access::get_Vektor(att1, att2);
Int16 kind = Convert::ToInt16(entity->get_Y()); // error

I got error about "object reference not set to an instance of an object

I think it's about the static method "getVektor()"...
Anyone can help me with this?
 
G

Guest

Oh sorry my fault. I changed just the Vektor_class from German-->English.

Correct spelling: public __gc class Vector {...

Method has correct Return-type: Vektor.
The problem has to be somewhere else in code.

Peter Oliphant said:
You spelled Vector wrong:
static Vektor* get_Vektor(String* e, String* p){

change to:
static Vector* get_Vektor(String* e, String* p){

[==P==]

Martin S. said:
the class:

public __gc class Vector {

private:
Double y, x, z;

public:
Vector() {
y(0),
x(0),
z(0)
{
}
};

Vektor(Double y, Double x, Double z){
y = x1;
x = x2;
z = x3;
}
Vector(String __gc* strVector); // "123.23,1232.23,4235345."

__property Double get_Y();
__property void set_Y(Double a);
__property Double get_X();
__property void set_X(Double b);
__property Double get_Z();
__property void set_Z(Double c);
};

Now i have another method which tries to return a vector:
class...
static Vektor* get_Vektor(String* e, String* p){

return new
Vektor(Convert::ToDouble(kind),Convert::ToDouble(domain),Convert::ToDouble(category));
}
..
end class


Vektor* obj = new Vektor();
obj = Access::get_Vektor(att1, att2);
Int16 kind = Convert::ToInt16(entity->get_Y()); // error

I got error about "object reference not set to an instance of an object

I think it's about the static method "getVektor()"...
Anyone can help me with this?
 
M

Martin S.

Martin said:
Oh sorry my fault. I changed just the Vektor_class from German-->English.

Correct spelling: public __gc class Vector {...

Correct spelling: public __gc class Vektor {...
 
T

Tamas Demjen

Martin said:
Int16 kind = Convert::ToInt16(entity->get_Y()); // error

What is entity? Your error message indicates that entity doesn't point
to any object, so you might have forgotten about creating that object.

Tom
 
M

Martin S.

Tamas said:
What is entity? Your error message indicates that entity doesn't point
to any object, so you might have forgotten about creating that object.

Tom

I create an Instance "obj" from Vektor, att1/att2 are two "Strings".
The Returntype is a Vektor with three elements. In the end I try to pull
out the Y-coordinate with the get-method from Vektor.

Vektor* obj = new Vektor();
obj = Access::get_Vektor(att1, att2);

Int16 kind = Convert::ToInt16(obj->get_Y()); // error
 
T

Tamas Demjen

Martin said:
I create an Instance "obj" from Vektor, att1/att2 are two "Strings".
The Returntype is a Vektor with three elements. In the end I try to pull
out the Y-coordinate with the get-method from Vektor.

It'd really help if you cut and pasted your code, because your doesn't
even compile. It's full of syntax errors, misplaced { and } symbols, etc.

Here's something that's similar to your code, and it works without an error:

#include "stdafx.h"

#using <mscorlib.dll>

using namespace System;

public __gc class Vektor
{

private:
Double y, x, z;

public:
Vektor()
: y(0), x(0), z(0)
{
}

Vektor(Double y1, Double x1, Double z1)
: y(y1), x(x1), z(z1)
{
}

__property Double get_Y() { return y; }
__property void set_Y(Double a) { y = a; }
__property Double get_X() { return x; }
__property void set_X(Double b) { x = b; }
__property Double get_Z() { return z; }
__property void set_Z(Double c) { z = c; }

};

public __gc class Access
{
public:
static Vektor* get_Vector(String* e, String* p)
{
return new Vektor(1, 2, 3);
}
};

int _tmain()
{
Vektor* obj = Access::get_Vector(S"", S"");
Int16 kind = Convert::ToInt16(obj->get_Y());
return 0;
}

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top