Static and non-Static member - Signature 
Author Message
 Static and non-Static member - Signature

Why doesn't the following syntax compile

class MyClass
{
    public void Parse(string value)
    {
        //
    }
    public static MyClass Parse(string value)
    {
        //
    }

Quote:
}

The error has todo with the fact that the methods have the same name and
take the same parameter type.  Doesn't the spec. make a difference between
static and non static members?


Tue, 12 Oct 2004 16:01:28 GMT  
 Static and non-Static member - Signature
I'm not sure, but my guess would be that this limit was imposed for clarity.
I mean, in calling these methods, how do you know the difference between
    MyClass.Parse("blabla");
and
    myClass.Parse("blabla");

If they do the same thing, then only one of them should exist anyway.
A sound decision, if you ask me.

--
Robert Jeppesen
MindCom AB

Quote:

> Why doesn't the following syntax compile

> class MyClass
> {
>     public void Parse(string value)
>     {
>         //
>     }
>     public static MyClass Parse(string value)
>     {
>         //
>     }
> }

> The error has todo with the fact that the methods have the same name and
> take the same parameter type.  Doesn't the spec. make a difference between
> static and non static members?



Tue, 12 Oct 2004 16:23:59 GMT  
 Static and non-Static member - Signature
You cannot overload methods based on return type, only on input
parameters.

--
Andreas H?kansson
Student of Software Engineering
andreas (at) selfinflicted.org


Quote:
> Why doesn't the following syntax compile

> class MyClass
> {
>     public void Parse(string value)
>     {
>         //
>     }
>     public static MyClass Parse(string value)
>     {
>         //
>     }
> }

> The error has todo with the fact that the methods have the same name and
> take the same parameter type.  Doesn't the spec. make a difference between
> static and non static members?



Wed, 13 Oct 2004 08:27:09 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Creating a static class from non static Framework classes

2. Pointers to non-static vs static functions

3. One Problem in Calling Static function from Non static function

4. static versus non static returnvalues

5. Static array containing non static objects and functions

6. Accessing non-static functions from a static function

7. static functions and non static variables

8. static functions with non-static variables!

9. Linking Error - Static vs. Non-Static

10. Linking Static DLL vs Non Static DLL

11. struct initialization (with static, const static members)

12. Getting pointer to non-static member function from C callback function

 

 
Powered by phpBB® Forum Software