how to link header files in c++

后端 未结 4 805
时光说笑
时光说笑 2021-02-04 15:27

I\'m new to programming in C++ with header files. This is my current code:

//a.h
#ifndef a_H
#define a_H
namespace hello
{
  class A
  {
    int a;
    public:
          


        
4条回答
  •  伪装坚强ぢ
    2021-02-04 16:20

    Currently you are compiling and linking only ex2.cpp but this file has makes use of class def and function calls present in a.cpp so you need to compile and link a.cpp as well as:

    g++ ex2.cpp a.cpp
    

    The above command will compile the source file(.cpp) into object files and link them to give you the a.out executable.

提交回复
热议问题