2

此代码在 Windows 上的 Visual Studio 2010 上正确编译,但在 Linux g++ 上出现此错误。谁能解释一下如何解决这个问题?

int bits;
T scale;
std::vector<U> TwoPowers;
U cropper;

template <typename T, typename U>
ConvertToBits<T,U>::ConvertToBits(int bits, T scale)
{
    this->bits = bits;
    this->scale = scale;
    for(long i = 0; i < 64; i++)
    {
        TwoPowers.push_back(static_cast<U>(pow(2.,i))); //error appears here
    }
    cropper = 0;
    for(int i = 0; i < bits; i++)
    {
        cropper += TwoPowers[i];
    }
}

错误信息:

错误:“pow”没有依赖于模板参数的参数,因此“pow”的声明必须可用[-fpermissive]

谢谢你。

4

1 回答 1

4

您需要#include <cmath>并在数学库中链接-lm(在某些系统上)。

于 2012-06-14T18:24:07.943 回答