473,387 Members | 1,790 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,387 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 4970

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
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.