search

Home  >  Q&A  >  body text

The c++ declaration is placed in the a.h file, and the implementation is placed in a.cpp. Why can the class implemented in a.cpp be used by referencing a.h in main.cpp?

Use visual studio to write a c program. The c declaration is placed in the a.h file, and the implementation is placed in a.cpp. Why can you use the class implemented in a.cpp by referencing a.h in main.cpp, while referencing a.cpp An error will be reported.
I don’t understand the rules very well. Can someone explain it to me?

为情所困为情所困2759 days ago881

reply all(2)I'll reply

  • PHPz

    PHPz2017-05-31 10:41:52

    First of all, the former means that you want to use this class. Considering that during the compilation process, you can use this class and function as long as there is a declaration of the class and function. When linking, the linker will look for the definition of the class and function in other files. In the latter, you do not have a declaration of the class implemented by a.cpp. The compiler does not know this class, so a compilation error occurs.

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-31 10:41:52

    It’s written more clearly here, you can understand it
    http://blog.csdn.net/praker/a...

    reply
    0
  • Cancelreply