【发布时间】:2019-02-04 17:16:52
【问题描述】:
我正在尝试对公差叠加进行建模。我制作了一个结构Layer,它包含公差范围的下限(tol[0])和上限(tol[1])。我想在tol[0] 和tol[1] 之间生成一个随机值并将其分配给val。
我的实现在结构中声明了uniform_real_distribution 类模板并在main() 中对其进行了初始化,但是我在编译过程中遇到了错误,这让我觉得我不能以这种方式使用类模板。
#include <random>
struct Layer {
double tol[2];
double val;
std::string name;
std::uniform_real_distribution<double> distribution;
};
int main()
{
Layer block;
block.tol[0] = .240;
block.tol[1] = .260;
std::default_random_engine generator;
block.distribution(block.tol[0],block.tol[1]);
block.val = block.distribution(generator);
return 0;
}
我从 g++ 收到以下错误:
error: no match for call to '(std::uniform_real_distribution<double>) (double&, double&)'
block.distribution(block.tol[0],block.tol1[]);
^
我创建了很多 Layer 结构,因此我希望将分布与结构相关联,但我不确定它是否可能了。
【问题讨论】:
-
您的错误信息与您的代码不匹配。请使用复制/粘贴,以便我们看到真实的东西。
-
@MarkRansom 这是我使用 gcc 4.8.1 版编译时遇到的错误
g++ -std=gnu++11 main.cpp -o main.exe