B
bsa
Hi,
This maybe a stupid question for which I apologies, but I couldn't
find a solutions so I'll ask.
I'm a newbie and I'm trying to do the following:
A have a base class called space that should accommodate all the
common operation over a dimensional object - vector, vertex or matrix.
public class Space
{
protected double [] data;
protected int columns;
protected int rows;
public Space( int _rows, int _columns )
{
rows = _rows;
columns = _columns;
data = new double[ rows * columns ];
}
public int Columns
{
get { return columns; }
}
public int Rows
{
get { return rows; }
}
public static Space operator +( Space rl, Space rr)
{
return new Space( rl.Rows, rl.Columns );
}
}
I also have a Vector class inherited from Space
public class Vector : Space
{
public Vector( ) : base( 1, 3 )
{
}
public static implicit operator Vector ( Space s )
{
return new Vector( s );
}
}
And I'm trying to use it as:
Vector v1 = new Vector( );
Vector v2 = new Vector( );
Vector v3 = v1 + v2;
And here I get the mentioned error CS0553.
How I should deal when I'm in need to implicitly convert one base
object to the inherited one?
Do you any of you have an idea how this could be solved?
thanks,
bsa
This maybe a stupid question for which I apologies, but I couldn't
find a solutions so I'll ask.
I'm a newbie and I'm trying to do the following:
A have a base class called space that should accommodate all the
common operation over a dimensional object - vector, vertex or matrix.
public class Space
{
protected double [] data;
protected int columns;
protected int rows;
public Space( int _rows, int _columns )
{
rows = _rows;
columns = _columns;
data = new double[ rows * columns ];
}
public int Columns
{
get { return columns; }
}
public int Rows
{
get { return rows; }
}
public static Space operator +( Space rl, Space rr)
{
return new Space( rl.Rows, rl.Columns );
}
}
I also have a Vector class inherited from Space
public class Vector : Space
{
public Vector( ) : base( 1, 3 )
{
}
public static implicit operator Vector ( Space s )
{
return new Vector( s );
}
}
And I'm trying to use it as:
Vector v1 = new Vector( );
Vector v2 = new Vector( );
Vector v3 = v1 + v2;
And here I get the mentioned error CS0553.
How I should deal when I'm in need to implicitly convert one base
object to the inherited one?
Do you any of you have an idea how this could be solved?
thanks,
bsa