473,406 Members | 2,705 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,406 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 4973

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.