Linking files in g++

后端 未结 4 1299
甜味超标
甜味超标 2020-12-01 11:17

Recently I have tried to compile a program in g++ (on Ubuntu). Usually i use Dev-C++ (on Windows) and it works fine there as long as I make a project and put all the necessa

4条回答
  •  余生分开走
    2020-12-01 11:39

    I assume that you have declared a member function (usually in a .h or .hpp file) but have ommited the respective definition of the member function (usually in a .cpp file).

    In c++, it is possible to declare a class like so:

    class foo {
      void x();
      void y();
    }
    

    with a cpp file that goes like so

    void foo::x() {
       do_something()
    }
    

    Note, there is no foo::y().

    This poses no problem to the compiling/linking process as long as the member function foo::y() is referenced nowhere throughout the compiled code.

提交回复
热议问题