我正在觀察一些我無法完全解釋自己的奇怪行爲。 的代碼看起來是這樣的:當使用std :: addressof時出現GCC 7編譯錯誤
#include <memory>
#include <vector>
#include <algorithm>
int main(){
std::vector<double> t1(10, 5.0);
std::vector<double*> t2(10);
std::transform(t1.begin(), t1.end(), t2.begin(), std::addressof<double>);
//std::transform(t1.begin(), t1.end(), t2.begin(), [](double& a){return &a;});
}
這裏是一個版本https://godbolt.org/g/YcNdbf 的問題打轉轉是此代碼編譯正常使用gcc4.9-6.3但在GCC 7.1失敗。 Cla也不喜歡它。
(編輯)錯誤從GCC 7.1的消息:
<source>: In function 'int main()':
8 : <source>:8:76: error: no matching function for call to 'transform(std::vector<double>::iterator, std::vector<double>::iterator, std::vector<double*>::iterator, <unresolved overloaded function type>)'
std::transform(t1.begin(), t1.end(), t2.begin(), std::addressof<double>);
^
In file included from /opt/compiler-explorer/gcc-7.1.0/include/c++/7.1.0/algorithm:62:0,
from <source>:3:
/opt/compiler-explorer/gcc-7.1.0/include/c++/7.1.0/bits/stl_algo.h:4281:5: note: candidate: template<class _IIter, class _OIter, class _UnaryOperation> _OIter std::transform(_IIter, _IIter, _OIter, _UnaryOperation)
transform(_InputIterator __first, _InputIterator __last,
^~~~~~~~~
/opt/compiler-explorer/gcc-7.1.0/include/c++/7.1.0/bits/stl_algo.h:4281:5: note: template argument deduction/substitution failed:
8 : <source>:8:76: note: could not resolve address from overloaded function 'addressof<double>'
std::transform(t1.begin(), t1.end(), t2.begin(), std::addressof<double>);
^
In file included from /opt/compiler-explorer/gcc-7.1.0/include/c++/7.1.0/algorithm:62:0,
from <source>:3:
/opt/compiler-explorer/gcc-7.1.0/include/c++/7.1.0/bits/stl_algo.h:4318:5: note: candidate: template<class _IIter1, class _IIter2, class _OIter, class _BinaryOperation> _OIter std::transform(_IIter1, _IIter1, _IIter2, _OIter, _BinaryOperation)
transform(_InputIterator1 __first1, _InputIterator1 __last1,
^~~~~~~~~
/opt/compiler-explorer/gcc-7.1.0/include/c++/7.1.0/bits/stl_algo.h:4318:5: note: template argument deduction/substitution failed:
8 : <source>:8:76: note: could not resolve address from overloaded function 'addressof<double>'
std::transform(t1.begin(), t1.end(), t2.begin(), std::addressof<double>);
^
Compiler exited with result code 1
不過,我不能完全弄清楚爲什麼它不工作。
在此先感謝任何人試圖幫助:)
Please be mo具體比「失敗」和「不喜歡它」。包含逐字錯誤消息。 – molbdnilo
'addressof'需要一個變量名稱,而不是類型名稱 – meowgoesthedog
對不起,我認爲在godbolt中查看它更容易,但我想你說得對,在這裏也有意義,所以我添加了它們;) | 和@meowgoesthedog不知道你的意思,變量通過變換傳遞給函數,只需要指定模板參數? – Christoph