Re: how do you overload methods...

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Mark Broadbent (nospam_at_nospam.com)
Date: 11/06/04


Date: Sat, 6 Nov 2004 20:17:18 -0000

I believe that the constructor of the TreeViewCollection has been set to
private so effectively it can't be inherited.
The error message is a bit misleading though (it suggests that there is a
public constructor that does not have zero args - and hence in that case you
would be able to call it from your derived class) .

see for instance...
http://www.groupsrv.com/dotnet/viewtopic.php?t=16350

Hope this helps

Br,

Mark.

P.S.
Benny, although this is really something that is open to your/ your company
preference, when naming types you should (IMHO) not prefix them with
"t" -that is really a Delphi thing (but if it works for you then please
ignore my advice).

P.P.S.
You mention that you do not understand overloading, well in essence creating
an overload means that you are adding an additional function call to a class
which has the same name that is distinguished by it's type signature.
For instance

    public void SayHello()
    {SayHello();} //just calling overload method to save code in class

    public void SayHello(string name)
    { string display = "Hello";
        if name.Length > 0
            display += name;
        Console.WriteLine(display);
    }

Which will mean that the Class would provide two method calls..
1 that allows you to SayHello without any arguments and the other to allow
you to SayHello with a string argument.

***I think you are also getting a little bit confused with overloading and
overriding - they are two DIFFERENT concepts. You should ideally read up on
both since they are crucial to good OOP***

"Thomas P. Skinner [MVP]" <tom@bu.edu> wrote in message
news:uKdDEgCxEHA.2788@TK2MSFTNGP15.phx.gbl...
> An overloaded method is a method that differs from all methods of the same
> name in so far as it has a different number or types of its arguments. A
> different return type does not constitute an overload. If you get an error
> stating that no overload has 0 arguments then you are calling a method
> with no arguments and you have no overloaded method that takes zero
> arguments. Either instantiate the class with a constructor call with
> arguments or provide an explicit constructor with zero arguments. In C# if
> you provide an overloaded constructor you no longer get a default
> constructor (zero arguments) and need to provide one. I think this is your
> problem.
>
> Thomas P. Skinner [MVP]
>
> "Benny Raymond" <benny@pocketrocks.com> wrote in message
> news:%238Ngd0BxEHA.4004@tk2msftngp13.phx.gbl...
>> I'm trying to change the way a treeview works just a bit, i'm pretty new
>> to C# and now i'm running into overloading. I tried the following code
>> and it's yelling at me saying that no overload method takes 0 arguments.
>>
>> #region tViewNodeCollection
>> public class tViewNodeCollection : TreeNodeCollection
>> {
>> private tView _owner;
>> private tViewNode _parent;
>> /// <summary>
>> /// Create a collection within a tViewItem
>> /// </summary>
>> /// <param name="parent"></param>
>> public tViewNodeCollection(tViewNode parent)
>> {
>> _parent = parent;
>> }
>> /// <summary>
>> /// Create a new instance of tViewNodeCollection
>> /// </summary>
>> /// <param name="owner"></param>
>> public tViewNodeCollection(tView owner)
>> {
>> _owner = owner;
>> }
>> /// <summary>
>> /// Create a new instance of tViewNodeCollection
>> /// </summary>
>> /// <param name="owner"></param>
>> public tViewNodeCollection(tView owner, tViewNode parent)
>> {
>> _owner = owner;
>> _parent = parent;
>> }
>> }
>> #endregion
>>
>>
>> so then I tried a series of different :this(something) but that started
>> scaring me since I really don't understand overloading - Could someone
>> shed some light on this for me?
>
>



Relevant Pages

  • Re: Proposal: Default Parameters/Named Parameters
    ... its referenced assemblies changes means the burned-in defaults would be ... Anders' mentioned the possibility of object initialization syntax that may ... If you didn't want to expose your constructor parameters as properties ... I like this a lot (especially since it's avoids the overload resolution ...
    (microsoft.public.dotnet.framework.clr)
  • Accessing controls on another form.
    ... >>> End Sub ... > Now the problem is I have used the overload in normal funtions and subs ... Dave, overloading a constructor is done the exact same way, although I'm ... Store the Form1 reference for later use. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Accessing controls on another form.
    ... >> Now the problem is I have used the overload in normal funtions and subs ... > Dave, overloading a constructor is done the exact same way, although I'm ... Store the Form1 reference for later use. ... > private Form1 myParent; ...
    (microsoft.public.dotnet.languages.vb)
  • Re: beginner c++ homework questions... if anyone knows how to do this, any help would be greatly app
    ... >4) Write a default constructor for the Money Class that initializes ... Money Class that initialises a Money object to $0.00. ... For Q5 you need to "overload" the constructor. ... understand "overload" look it up or ask your instructor to explain. ...
    (comp.lang.cpp)
  • Re: ADO.NET converting numerical zero to NULL
    ... Use caution when using this overload of the SqlParameter constructor to ... > When I fill my parameters, everything seems to work just fine, except> when I need to fill an INT parameter with the value of 0 (zero). ...
    (microsoft.public.dotnet.framework.adonet)