Question about operator overloading

V

Vinod Nair

I dont understand why overloading operator includes
'static' key word, when we are clearing delaing with
instances and not types.

Ex:

public static Vector operator * ( double lhs, Vector rhs)
{
// implementation
}

Why is there static keyword there?
 
S

Simon Johnson

Vinod Nair said:
I dont understand why overloading operator includes
'static' key word, when we are clearing delaing with
instances and not types.

Ex:

public static Vector operator * ( double lhs, Vector rhs)
{
// implementation
}

Why is there static keyword there?

I'll hazard a guess.. I think that the operator is actually short hand.. for
example:

C = A * B; --> C=Vector.*(a,b);

I know you can't actually use the second part as working code but I think
this is what it's meant to represent.

If this is true.. then it seems like a pretty good reason to have the static
keyword :)

Simon.
 
B

Bjorn Abelli

...
I dont understand why overloading operator includes
'static' key word, when we are clearing delaing with
instances and not types.

You're working with instances only as local variables *within* the method.

You're not dealing with "this" instance.

// Bjorn A
 

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