typedef 一个 sc_fixed 但出现模板错误

typedef an sc_fixed but got template error

尝试在 Visual Studio 2017 中定义一个简单的 sc_fixed 类型:

#include <systemc.h>
#include <sysc/datatypes/fx/sc_fixed.h>   # just in case
....
typedef sc_fixed<16, 4> fixed_type;
....

此 typedef 行导致错误:

E0864: sc_fixed is not a template

不知道为什么会出现这个错误,甚至包括 sysc/datatypes/fx/sc_fixed.h。为什么说“不是模板”?

来自 SystemC 附带的 INSTALL 文件

SystemC 2.3 includes a fixed-point package that is always built. When compiling your applications with fixed-point types, you still have to use compiler flag -DSC_INCLUDE_FX. Note that compile times increase significantly when using this compiler flag.

以您的代码为例

#include <systemc.h>
#include <sysc/datatypes/fx/sc_fixed.h>

#include <iostream>

typedef sc_dt::sc_fixed<16, 4> fixed_type;

int sc_main(int, char**){
    fixed_type ft(1.25);
    std::cout << "ft = " << ft << '\n';
    return 0;
}

给我输出

ft = 1.25

作为一个警告,最好检查您的特定 SystemC 版本的文档,因为我相信这个 #define 可能 已在 2.3.3 中删除(我我正在使用 2.3.2) 我不确定。

我在我的一个 C++ 程序中收到相同类型的错误消息 - E0864 - unique_ptr 不是模板

我通过将其添加到我的头文件中设法消除了我程序中的这个错误。

#include <memory>

我的程序使用它成功编译。如果有帮助,我正在使用 Visual Studio 2019。