Re: my first class - getting an error

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



vinnie wrote:
I did my first project with the classes, but i get an error that i
don't understand, and so don't know how to correct it.

I'm not sure what the problem you're having interpreting the error is, but I _suspect_ you are being led astray by the "...and no extension method blah blah blah" part. A similar example is the error in .NET 2.0 that says the "best overload" doesn't take certain parameters.

This is a pet peeve of mine, with respect to the compiler errors. In some cases, in a well-intentioned effort to provide you with additional guidance, the compiler introduces some concept that you may not even be aware of, completely confusing the issue.

My guess is that if you just look at the very first clause in the error -- "'mixed_class.Program' does not contain a definition for
> 'Calculus'" -- you'd figure it out on your own. But with all that other stuff, a "newbie" is left scratching their head trying to figure out what it _all_ means.

In your specific situation, the issue here is that you are using an instance of a "Program" class, "So", to try to call the "Calculus" method. But the "Calculus" method exists in the "summing" class, not the "Program" class. So what you actually need is an instance of the "summing" class.

In fact, since at least right now your "Program" class only contains a single static method, I don't see any reason to ever instantiate it.

Change these two lines:

Program So = new Program();

so that it instead reads:

summing So = new summing();

and the error should go away.

As a more general rule, you should really try hard to break compiler messages (errors or otherwise) into small enough pieces so that you can really understand what they are saying. The error you got is pretty clear about what the problem is, as long as you can avoid getting overwhelmed by the stuff you don't understand.

In this case, the compiler clearly explained that the "Program" class you're trying to use doesn't contain the "Calculus" method that you're trying to call. That should have been able to lead you directly to realizing that you had the wrong class when you were trying to call "Calculus". Since you should have expected the compiler to be looking for "Calculus" in the "summing" class, from that error it should have been simple to just figure out why the compiler is looking at the wrong class. And of course, that turns out to be because the variable is the wrong type. :)

Pete
.



Relevant Pages

  • Re: C++ to VB conversion and preprocessor definition
    ... The #define preprocessor definition tells the compiler to effectively ... perform a search and replace on the sourcecode as it is compiling, replacing ...
    (microsoft.public.dotnet.languages.vb)
  • Re: FreeRTOS / SafeRTOS in a Medical Device
    ... delete "in blah blah blah" ... Which is why it is difficult to do validation for a GCC compiler compared to a compiler from say Byte craft where they have all the documentation from day 1 and control the process. ... if I was to take that landing gear and integrate it ... onto another plane then I would need the entire lifecycle and design data so ...
    (comp.arch.embedded)
  • Re: MODULEand USE versus Argument Passing
    ... I am quite aware of special array type cases, which show some compiler ... for three interfaces (Module, Subroutine contained in module, and external ... -| COMMON blah blah I,J, blah blah ...
    (comp.lang.fortran)
  • broken samples....
    ... mostly for embarrasing reasons like: ... Now that your compiler got better it ...
    (microsoft.public.vc.language)
  • Declaring constants within the scope of a class
    ... // blah blah blah ... integral type is not allowed in C++, but the compiler is giving a wrong ...
    (comp.lang.cpp)