Re: How to solve the error "The local variable may not have been instantiated"?



Shawn wrote:
....
Thank you for your help. I didn't forget "= null;". My program still doesn't work. This is what I saw. If you insist, maybe it has to do with settings of compiler. I know regards to warnings, user can make selections so that somethings are considered as warnings, some not.

The initialization issue is an error, not a warning. The compiler should
never compile something with a possibly not initialized local variable,
because the results are undefined.

....
This won't work for me. I simplified my program in the posting. In my real program, after myClass object was created, the object was used several times. So it cannot be inside the if block:

return new MyClass(..); //myClass object created here

You should not get the "may not have been initialized" for a variable
that has an initial value in its declaration, as in:

MyClass myClass = null;

Make sure you only have one declaration with identifier myClass, so that
there is only one variable with that name.

If you are still having trouble, please post a short self-contained
example that reproduces it.

Patricia
.



Relevant Pages

  • Re: problem using self built DLL
    ... runtime, the compiler still has to know about the class and all its methods, members, its ... called MyClass, AND YOU HAVE SAID NOTHING MORE ABOUT IT! ... declaration, wherein you promise to say something later. ... MyClass has no member function or member ...
    (microsoft.public.vc.mfc)
  • Re: problem using self built DLL
    ... says to the compiler, "I will tell you about this class in detail before you need it". ... which says "This is a class with no member variables and no methods". ... class declaration in the header file. ... called MyClass, AND YOU HAVE SAID NOTHING MORE ABOUT IT! ...
    (microsoft.public.vc.mfc)
  • Re: A question on incomplete definitions
    ... This is a tentative forward declaration of x. ... The compiler is allowed to give warnings for code which is correct but looks ... forward declaration at all of a static const integer in your code. ...
    (comp.lang.c)
  • Re: Event never used warning message
    ... The compiler is issuing the warning because it is ... will not issue warnings below a certain level. ... >I have created an event and delegate combination for use in a user control>when I place it on a form. ... > 1) How do I get rid of that warning (besides creating an empty> declaration) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Is it standard and practical to use long long types?
    ... > right option for putting the compiler in conforming mode. ... > compiler is invoked with the extensions disabled, ... Bogus/idiotic warnings when all warnings are enabled. ... GCC does not fully support C99, yet ansi invokes it's C99 spirit. ...
    (comp.lang.c)