473,320 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

error CS0553: user-defined conversion to/from base class

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
Nov 16 '05 #1
4 4960

I think it is saying you don't need to implement the below function in the
derived class. C# inherently provides this for you.

public static implicit operator Vector ( Space s )
{
return new Vector( s );
}
---
"bsa" <bs****@hotmail.com> wrote in message
news:3d*************************@posting.google.co m...
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

Nov 16 '05 #2
bsa
But not implementing this function, the code is still not compiled
because of error CS0029: Cannot implicitly convert type.
Which means although the compiler provide this function it doesn't use
it !

bsa

"NaraendiraKumar R. R." <na********@nospam.com> wrote in message news:<e4*************@tk2msftngp13.phx.gbl>...
I think it is saying you don't need to implement the below function in the
derived class. C# inherently provides this for you.

public static implicit operator Vector ( Space s )
{
return new Vector( s );
}
---
"bsa" <bs****@hotmail.com> wrote in message
news:3d*************************@posting.google.co m...
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

Nov 16 '05 #3
To solve that error, you will have to do this ...
Vector v3 = (Vector)(v1 + v2);

OR

you can override the + operator in your Vector class.

-Naraen
---
"bsa" <bs****@hotmail.com> wrote in message
news:3d**************************@posting.google.c om...
But not implementing this function, the code is still not compiled
because of error CS0029: Cannot implicitly convert type.
Which means although the compiler provide this function it doesn't use
it !

bsa

"NaraendiraKumar R. R." <na********@nospam.com> wrote in message

news:<e4*************@tk2msftngp13.phx.gbl>...
I think it is saying you don't need to implement the below function in the derived class. C# inherently provides this for you.

public static implicit operator Vector ( Space s )
{
return new Vector( s );
}
---
"bsa" <bs****@hotmail.com> wrote in message
news:3d*************************@posting.google.co m...
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

Nov 16 '05 #4
If it's any consolation, I came up with exactly your situation in an application quite similar to yours and tried the same solution (creating an implicit conversion from the base class to the child class) which resulted in the CS0553 error. I had a general Vector class and wanted to create a special case of it Vector3D. In doing this, none of the operators on the base class could be used to implicitly return values of the derived class, and I ended up writing all over again (albeit simpler) them in the Vector3D class.

It wouldn't have been so bad, except that Microsoft, in its help on this particular error message said that I don't need such a thing. Silly me.

-&&
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Morten Gulbrandsen | last post by:
Hello programmers, I think something is wrong with my administration, Basically I get these messages, ERROR 1005 at line 9: Can't create table '.\company\department.frm' (errno: 150) ERROR...
8
by: Glenn A. Harlan | last post by:
Why am I receiving the below error when calling - Path.GetTempFileName() The directory name is invalid. Description: An unhandled exception occurred during the execution of the current web...
3
by: Steve - DND | last post by:
I was wondering if anyone can point me to some articles or practices they use for dealing with errors in their applications; particularly in an n-tier design. I am trying to find one way to...
2
by: hansiman | last post by:
I'm wondering how best to present exception messages to a user. In a try catch I catch an OleDb.OleDbException. The error could be a COLUMN REFERENCE constraint error (by a deletion attempt). ...
2
by: arsisthesis | last post by:
Hi all, I have a curious problem with the ERROR 1044 and 1045: -system: OS X 10.4.3 (bash shell) -bash schell prompt: /~ kssun$ -I have set passwd to 'kssun' -I set path:...
16
Frinavale
by: Frinavale | last post by:
The following article is directed at people who are experiencing an HTTP/1.1 500 Internal Server Error while using Visual Studio 2003. The error message typically sounds something like: The web...
0
by: .nLL | last post by:
Erorr is --------------------- Microsoft VBScript runtime error '800a0046' Permission denied /a.asp, line 3 -----------------------
0
by: calvinkwoo3000 | last post by:
My window application run property before i set a password at mdb file. Below is my connection string that before and after set password conn = new...
18
by: pereges | last post by:
Hi, I'm thinking of having a seperate module in my project that deals with the exceptions and errors as they occur in a C program. Is this a good idea ? I thought of doing this because it is...
5
by: Cirene | last post by:
I just deployed my new ASP.NET (3.5 FW) site to the hosting company I'm using, webhost4life. NOTE: I HAVE deployed other SQL Server sites to the same account with no issues. Now I'm getting...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.