Undefined Reference to

后端 未结 6 914
生来不讨喜
生来不讨喜 2020-12-01 06:28

When I compile my code for a linked list, I get a bunch of undefined reference errors. The code is below. I have been compiling with both of these statements:



        
6条回答
  •  無奈伤痛
    2020-12-01 07:06

    Another way to get this error is by accidentally writing the definition of something in an anonymous namespace:

    foo.h:

    namespace foo {
        void bar();
    }
    

    foo.cc:

    namespace foo {
        namespace {  // wrong
            void bar() { cout << "hello"; };
        }
    }
    

    other.cc file:

    #include "foo.h"
    
    void baz() {
        foo::bar();
    }
    

提交回复
热议问题