473,320 Members | 2,048 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.

Wrong overload



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();
}
Nov 16 '05 #1
3 1034
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

Nov 16 '05 #2
hmmm

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

"a post somewhere in the past"

http://groups.google.com/groups?q=ov...phx.gbl&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
Nov 16 '05 #3
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
Nov 16 '05 #4

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

Similar topics

1
by: Piotre Ugrumov | last post by:
I'm following your help. I have written the overload of the operator <<. This overload work! :-) But I have some problem with the overload of the operator >>. I have written the overload of this...
3
by: Piotre Ugrumov | last post by:
I have done the overload on the operator >> and << in the class Attore. These 2 overload work correctly. I have done the overload of the same overload in the class Film. The class film ha inside...
1
by: Chiller | last post by:
Ok, I've implemented a few changes to the code and the bool functions now seem to be functioning correctly; however, I think I'm doing the convertions incorrectly because the values printed out...
34
by: Pmb | last post by:
I've been working on creating a Complex class for my own learning purpose (learn through doing etc.). I'm once again puzzled about something. I can't figure out how to overload the assignment...
13
by: Vladimir Granitsky | last post by:
Hi guys, Please, look at the code below and try to step into it. The compiled code calls the loosely typed method public void Method1(object o) !?!? Am I right that C# compiler does wrong...
10
by: Richard Bixler | last post by:
Hello - I have a project in VB.NET (framework version 1.1), in which I use the function InStr in the following form: Public Function InStr(ByVal String1 As String, ByVal String2 As String,...
14
by: =?Utf-8?B?R3JlZ2cgV2Fsa2Vy?= | last post by:
Hopefully someone can set me straight on this issue. I was testing some code where I have a method that is being overriden. The method overrides were working fine until I passed a literal 0 (int...
5
by: jknupp | last post by:
In the following program, if the call to bar does not specify the type as <int>, gcc gives the error "no matching function for call to ‘bar(A&, <unresolved overloaded function type>)’". Since bar...
1
by: fabian.lim | last post by:
Hi all, Im having a problem with my code. Im programming a vector class, and am trying to overload the () operator in 2 different situations. The first situation is to assign values, e.g. Y =...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

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.