This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Global Class Decleration

Hi,

I am using uVision4 for LPC3250.

I declare my class in my header file and define its functions in the corresponding cpp file.

My question is this, how can I reach the object of this class when I create it in another file.

For example, in a.cpp:

MyClass MyObject;

in b.cpp

MyBoject.value = 5;

I want my object to be global.

Thanks for your helps.

Parents
  • "I wrote in b.cpp

    extern MyClass MyObject;

    when I use ... I get the error"

    And:

    "I made the extern declerations in the header file but I still have error."

    Do you understand how header files work?
    They are just simple text inclusion - so, if it didn't work by typing the 'extern' directly in the .cpp file, then it obviously also won't work just by putting it in a header!

    Note that what you are getting is a Linker erro - so the code must have Compiled OK?

    So you need to look at why the Linker cannot find a definition for this symbol in its input object modules and/or libraries...

    Are you sure that a module that defines MyObject is being linked?

Reply
  • "I wrote in b.cpp

    extern MyClass MyObject;

    when I use ... I get the error"

    And:

    "I made the extern declerations in the header file but I still have error."

    Do you understand how header files work?
    They are just simple text inclusion - so, if it didn't work by typing the 'extern' directly in the .cpp file, then it obviously also won't work just by putting it in a header!

    Note that what you are getting is a Linker erro - so the code must have Compiled OK?

    So you need to look at why the Linker cannot find a definition for this symbol in its input object modules and/or libraries...

    Are you sure that a module that defines MyObject is being linked?

Children