我使用G ++ 4.4.1,並在namespace.I內我的課具有參考與傳遞的問題有創建測試程序低於能夠證明我的問題,並希望如果有人知道爲什麼它不會編譯通過引用傳遞的C++與命名空間中的類
#include <stdio.h>
namespace clshw
{
class hwmgr
{
private:
hwmgr() {};
public:
~hwmgr() {};
static hwmgr* Instance();
int Read(int crumb, int& state);
private:
static hwmgr* instance;
};
}
namespace clshw
{
hwmgr* hwmgr::instance = NULL;
hwmgr* hwmgr::Instance()
{
instance = new hwmgr;
return instance;
}
int hwmgr::Read(int crumb, int state)
{
state = true;
return 1;
}
}
using namespace clshw;
hwmgr *hw = hwmgr::Instance();
int main()
{
int state;
int crumb;
int ret = hw->Read(crumb, state);
}
錯誤從編譯如下:
test7.cpp:30:錯誤:原型「詮釋clshw :: hwmgr ::閱讀(INT,INT) 「不匹配任何類 'clshw :: hwmgr' test7.cpp:13:錯誤:候選人爲:int clshw :: hwmgr ::閱讀(INT,INT &)
TIA, 基思
缺少&由REF IN DEFN傳遞狀態。 – hmjd
錯誤似乎很闡述。 – chris