我真的是新的C++,我無法解決下面的編譯錯誤。C++ begineer:使用命名空間錯誤
data_structure.h
#include <stdint.h>
#include <list>
namespace A {
class B {
public:
bool func_init(); // init
};
};
data_structure.cpp
#include "data_structure.h"
using namespace A;
bool B::func_init(){
std::cout << "test init" << std::endl;
return true;
}
的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;
}
我有一個錯誤,如下
未定義的參考`A :: B :: func_init()」
敬請指教,爲什麼我不能得到func_init,儘管它已經被聲明爲public?我也在那裏提供了正確的命名空間。
希望對此有所迴應。
我的錯,那是CPP文件從一開始,不是c文件。但我仍然有compliation – xambo 2013-04-10 14:46:32
@xambo這個問題你怎麼編譯? – 2013-04-10 14:48:31
g ++ main.cpp -o test – xambo 2013-04-10 14:51:03