我有這樣的代碼:拷貝構造函數奇怪的編譯錯誤
namespace js0n
{
struct json
{
typedef int json_object;
json(){}
json(json_object const& other)
{
}
json& operator=(json_object const& other)
{
return *this;
}
};
typedef json::json_object json_object;
}
線js0n::json json(js0n::json_object());
給出編譯錯誤。
int main()
{
js0n::json json(js0n::json_object());
return 0;
}
請注意,我剔除了大部分代碼,因爲它不會對錯誤負責。我究竟做錯了什麼?
錯誤消息:
test.cpp: In function 'int main()':
test.cpp:9:8: error: request for member 'parse' in 'json', which is of non-class type 'js0n::json(js0n::json_object (*)()) {aka js0n::json(int (*)())}'
賦值運算符,即(json = json_object();
)的工作得很好。
Way.Too.Much.Code。請刪除*任何*不必要的,幷包括你得到的錯誤。 – Xeo
你可以忽略很多。問題在於複製構造函數。 – user1095108