我正在观察一些我无法完全解释自己的奇怪行为。 的代码看起来是这样的:当使用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