C++ begineer:使用命名空间错误

xam*_*mbo 2 c++

我是C++的新手,我无法解决下面的编译错误.

data_structure.h

#include <stdint.h>
#include <list>

namespace A {

        class B {
            public:

            bool        func_init(); // init
            };

};
Run Code Online (Sandbox Code Playgroud)

data_structure.cpp

#include "data_structure.h"

using namespace A;

bool B::func_init(){

    std::cout << "test init" << std::endl;
    return true;

}
Run Code Online (Sandbox Code Playgroud)

main.cpp中

#include    <iostream>
#include    "data_structure.h"

using namespace A;

int main( int argc, char **argv ) {

    A::B s;
    s.func_init();

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我有一个错误如下

未定义的引用`A :: B :: func_init()'

请告知为什么我不能获得func_init,尽管它被宣布为公开?我在那里也放了正确的命名空间.

对任何回复表示感谢.

Luc*_*ore 5

这是一个链接器错误,因此您可能没有编译所有源文件,或将它们链接在一起,或者使用C编译器(我看到您的文件有扩展名.c,有些编译器将它们视为C源代码).