-3

I'm implementing the Discrete Fourier Transform for a school assignment, and I've created a DFT class which constructs the transformation matrix. For some reason, when I instantiate a DFT object in main() everything works fine, but the matrix isn't constructed properly if I use the unnamed namespace.

Works:

int main()
{
    DFT matrix(size);
    ...
    matrix.Transform(data);
    ...
}

Doesn't work:

namespace
{
    DFT matrix(size);
}

int main()
{
    ...
    matrix.Transform(data);
    ...
}

Compiler bug, or am I misremembering how the unnamed namespace works?

4

2 回答 2

0

只是一个疯狂的猜测:

namespace
{
    DFT matrix(size);
}

它从哪里来size?请记住,这将在运行之前main构建。

于 2012-04-20T10:48:50.820 回答
0

这里的问题是您实际上不能像这样从未命名的命名空间调用构造函数......

namespace {
    DFT matrix(size);
}

实际上是声明一个函数。另一方面,

namespace {
    DFT matrix;
}

可以工作,但会使用零初始化器。

于 2016-10-20T16:39:45.877 回答