也就是说,客户端机器上的本地文件具有默认的"主机","端口","用户"值等,这样我每次都不必在命令行输入它们?
我试图在C++类中包装一个C结构,以利用内存管理等.我让这个结构成为私人成员,并提供了一个提供访问权限的公共功能.返回类型是常量,因为将对象作为参数的所有函数都const在其签名中.
#include <gsl/gsl_rng.h>
class GSLRand {
gsl_rng* r_; // see links below
public:
GSLRand() {
gsl_rng_env_setup();
r_ = gsl_rng_alloc(gsl_rng_default);
}
~GSLRand() {
gsl_rng_free(r_);
}
const gsl_rng* rng() {
return r_;
}
};
Run Code Online (Sandbox Code Playgroud)
这一切都编译得很好.当我变得聪明并尝试添加复制构造函数时,就会出现问题.将它介绍到类中......
public:
....
GSLRand(const GSLRand& R) {
r_ = gsl_rng_alloc(gsl_rng_taus);
gsl_rng_memcpy(r_, R.rng());
}
....
Run Code Online (Sandbox Code Playgroud)
我得到以下编译器错误:
GSLRand.h: In copy constructor ‘GSLRand::GSLRand(const GSLRand&)’: GSLRand.h:35: error: passing ‘const GSLRand’ as ‘this’ argument of ‘gsl_rng* GSLRand::rng()’ discards qualifiers
我在Mac上使用g ++.我尝试了不同的变种,仍然无法弄清楚我是如何混淆编译器(或我自己!).有趣的是,当我const从中删除说明符时,我得到了相同的错误rng().
有任何想法吗?
有关所用函数的文档: 随机数生成,"环境变量"和"复制生成器"部分.