Re: path error code, why?

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



vinnie wrote:
Oh, ok, let's see if i understood right:

Doesn't look like it.

1) a function can only pass back one value (such as using return );

A function can only have at most one _return_ value. This is the value that, when the function name itself is used in an expression, is used in the expression in which the function name is used.

However, a function can pass back arbitrarily many values, via a variety of mechanisms, including the return value (which itself could encapsulate multiple values, if it's a struct or class instance), passing variables by reference, and passing reference types by value, all of which can be used simultaneously.

2) i was trying to make one function to return more values, which is
wrong;

It's not wrong as long as there's a good reason to do so. If you have a good reason for having two "out" parameters, that's fine.

3) to make that function to pass back more values, i need to make it a
method, that i achieve with the using of VOID.

In C#, everything is a function. Or everything is a method. Or both. It just depends on how you use the words.

But regardless of how you use the words, not all functions (or methods) return a value. Some have "void" as the return type, meaning they don't return anything.

Is this required if you intend to pass back multiple values? No, not at all. You can have a return value _and_ you can have parameters passed by reference, for example.

But, the example of code you posted does not include a line of code that returns anything, so it sure seems as though declaring the function as returning a "double" is an error.

_In your specific example_ it appears that the correct thing to do is simply change the function's return type from "double" to "void". But this is not the required solution. You could instead actually return a value from within the function, and that would also make the error go away.

Now, if you finally understand all that...

In addition to having mis-matched return type as it relates to the actual code, your CalcolaPercentuale() function has some other oddities:

* You initialize the "out" parameters to 0 and then immediately after assign new values to them. There's no point in initializing them to 0 in this case; it's useless code (hopefully removed by an optimizer somewhere along the line, but still...you should work on not writing useless code).

* You have two other parameters that don't appear to be used at all: "a" and "b". They are never referenced in the code you posted, so why do they even exist?

* In the Main() function, you've declared local variables with the same name as the static members "percentuale" and "valore". I'm surprised you don't get a compiler warning about that, but they hide the static members from code in the Main() method. This may be related to the previous issue, since the CalcolaPercentuale() function uses the static members; perhaps you meant to use the parameters "a" and "b" instead of the static members.

On this last point: if you meant to use the parameters "a" and "b", that begs the question: why have the static members at all? Conversely, if you meant to have the static members, why bother with the local variables? Possibly this would also lead to the question: why bother passing the values into the CalcolaPercentuale() function? Since they are already accessible, if you always intend for the function to use those specific values, they need not be passed in every time. Just use the static members directly (as the function does now) and remove the "a" and "b" parameters (which aren't being used now anyway).

Pete
.



Relevant Pages

  • Re: Best way to use static method functions from MC++ lib in VB.NET
    ... class library DLLs automatically referenced by the Visual Studio .NET IDE. ... Certain project types add references to other .NET DLLs (such as the ... declare a "ConsoleEx" class with static members that were meant to augment ... > I create a reference to the library from a VB.NET application and I can ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Is this thread safe?
    ... StringBuilder bld = new StringBuilder; ... StreamWriter sw = File.AppendText; ... The String class is immutable, so once the reference has been passed in, even if other threads are reading from the class, that wouldn't affect the thread executing this method. ... Getting the StreamWriter is thread-safe, with File.AppendTextbeing a static method and so falls under the "thread-safe" qualification for static members. ...
    (microsoft.public.dotnet.framework)
  • Re: a very tricky question...
    ... members donot reside in the object but we are accessing static members ... using object reference technique. ... logically replaces a method reference with a static reference. ...
    (comp.lang.java.gui)
  • Re: What is the difference between class and type.
    ... Michael Borgwardt wrote: ... > That's not entirely true - with static members accessed through a reference ... Chris Smith - Lead Software Developer/Technical Trainer ...
    (comp.lang.java.programmer)