記錄乙個今天寫c++遇到的乙個錯誤,**是這樣的:
編寫過程中做的型別檢查並沒有提示任何錯誤,一眼看過去也沒什麼問題,但是並不能通過編譯,錯誤資訊是下面這個:list<
char
*> list =
;vector v;
v.assign
(list.
begin()
, list.
end())
;
c2440 「初始化」: 無法從「_ty」轉換為「_objty」
可惜我才疏學淺,並不能看懂
於是就想隨便試一試,給初始化列表多加了幾個值,然後型別檢查就出現了錯誤,這樣問題就清晰起來了。上面的第一條語句因為不能作為合適的初始化列表,因此被編譯器當成:
因為"hello"的型別是char *,而begin(「hello」)的型別也是char *,所以上面這條語句實際呼叫的是接受迭代器型別的建構函式list<
char
*>
list
("hello"
,"world"
);
直觀一些,這條語句等價於:
而實際上這兩個位址並非指向同乙個物件的不同元素,因此這個初始化的結果自然不對。list<
char
*>
list
(begin
("hello"),
end(
"world"))
;
問題的根源在於沒辦法把const char*轉換為char*
感覺還蠻隱蔽的,要是多寫或者少寫幾個元素都不會碰到這個結果hhh
啟動PHP時提示初始化錯誤
root yhoo php sbin php fpm t 08 dec 2015 23 08 13 error failed to open configuration file usr local php etc php fpm.conf no such file or directory 2 0...
啟動PHP時提示初始化錯誤
root yhoo php sbin php fpm t 08 dec 2015 23 08 13 error failed to open configuration file usr local php etc php fpm.conf no such file or directory 2 0...
啟動PHP時提示初始化錯誤
root yhoo php sbin php fpm t 08 dec 2015 23 08 13 error failed to open configuration file usr local php etc php fpm.conf no such file or directory 2 0...