使用clog计算复数的自然对数时,如何解决出现的歧义?
How can I resolve the occuring ambiguity when using clog for computing the natural logarithm with complex numbers?
我有一个复杂的双精度数组 eigenvalues
,我想通过使用 clog
.
获得每个条目的自然对数
for (int i = 0; i < n; ++i)
{
qq[i] = clog(eigenvalues[i]);
}
我已经放弃 using namespace std;
但我仍然得到 error: reference to 'clog' is ambiguous
。
如何明确表示我想使用 complex.h
中的 clog
而不是 iostream
中的 clog
?
如果没有 using namespace std
,我无法使用 gcc 7.3 重现这一点,但通常来自 C 头文件的所有函数都驻留在全局命名空间中。因此,您应该能够通过在 ::
:
前加上前缀 clog 来解决歧义
for (int i = 0; i < n; ++i)
{
qq[i] = ::clog(eigenvalues[i]);
}
我有一个复杂的双精度数组 eigenvalues
,我想通过使用 clog
.
for (int i = 0; i < n; ++i)
{
qq[i] = clog(eigenvalues[i]);
}
我已经放弃 using namespace std;
但我仍然得到 error: reference to 'clog' is ambiguous
。
如何明确表示我想使用 complex.h
中的 clog
而不是 iostream
中的 clog
?
如果没有 using namespace std
,我无法使用 gcc 7.3 重现这一点,但通常来自 C 头文件的所有函数都驻留在全局命名空间中。因此,您应该能够通过在 ::
:
for (int i = 0; i < n; ++i)
{
qq[i] = ::clog(eigenvalues[i]);
}