我有以下代码:
template<typename flow_t, typename cost_t>
struct min_cost_flow {
static const flow_t FLOW_INF = numeric_limits<flow_t>::max() / 2;
static const cost_t COST_INF = numeric_limits<cost_t>::max() / 2;
...
};
不幸的是,它无法编译,并给出错误“ [...]对`min_cost_flow :: COST_INF的未定义引用”。
我尝试过的两个我不喜欢的修复程序包括将const
更改为constexpr
(可以在我的计算机上成功编译,但不能在具有旧版gcc的其他计算机上编译),并在下面定义常量的值类,但这将值与我要使用它们的位置相隔太远。还有其他想法吗?