Wrong overload

  • Thread starter Alexander Muylaert
  • Start date
A

Alexander Muylaert

Hi,

for some reason my formatter doesn't write correct on Compact framework.

The following piece of code will demonstrate very weird behaviour with
overloading.

For some reason the inherited binarywriter doesn't take the right procedure.

He will always write 8 bytes for an integer (int), uses the Write(decimal)

Am I supposed to override ALL the methods with the same name when I
inherited one? Is this true or does the source below generates a bug?

I had this problem running on compact framework, since the other framework
supports Write(decimal) on the binarywriter.

kind regards

Alexander





private static int X = 20041101;


private class MyWriter : BinaryWriter{


public MyWriter(Stream aStream) : base(aStream){}

/* since this is not added inside the pocket framework,

i kind added it myself. Storing it as double is not a problem,

since we are reading it as double*/

public void Write(decimal value){

Write(decimal.ToDouble(value));

}

}



private void button1_Click(object sender, System.EventArgs e) {

Stream S = new MemoryStream();

MyWriter W = new MyWriter(S);


W.Write(X);


label1.Text = S.Position.ToString();


}
 
A

Alexander Muylaert

Hi

Overriding all the overloaded methods doesn't help neither.

for some reason the Write(decimal) is always used when writing ordinal
values.

It looks likes the compiler is always taking the best method match on level
"this". He doesn't even check the "base" level for methods.

Please advise because this is really enoying.

kind regards

Alexander
 
A

Alexander Muylaert

hmmm

It seems to be implemented this way. Weird but true.

"a post somewhere in the past"

http://groups.google.com/[email protected]&rnum=2

"end of post"

Reimplementing all the same methods with the "new" in front does solve this
problem.

Problem is fixed for current version of the binary writer, but I'm pretty
sure this is going to cause bugs with future
releases of the framework. What if they add a method to the binary writer?
I need to check every piece of code if they didn't add a method... then I
rather don't have overloading at all.

kind regards

Alexander
 
A

Alexander Muylaert

Anyway

I still want to say that I don't like this kind of behaviour.

Since most of the .net compatible languages behave different. VB.Net, C++,
Delphi.net ...

What if we share classes? Isn't .net designed to allow us this?

kind regards

Alexander
 

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