Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/153.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 指针赋值_C++ - Fatal编程技术网

C++ 指针赋值

C++ 指针赋值,c++,C++,我有以下模板结构: template <typename scalar_type> struct postc_params{ scalar_type delta; unsigned int time_horizon; matrix_math::matrix<scalar_type> dynamics; boost::shared_ptr<continuous_set> invariant_set_ptr; boost

我有以下模板结构:

template <typename scalar_type>
struct postc_params{
    scalar_type delta; 
    unsigned int time_horizon; 
    matrix_math::matrix<scalar_type> dynamics;
    boost::shared_ptr<continuous_set> invariant_set_ptr;
    boost::shared_ptr<continuous_set> input_set_ptr;
    boost::shared_ptr<continuous_set> initial_set_ptr;
};
transform函数返回类型为的指针

boost::shared_ptr<continuous_set>
boost::共享
使用此代码,我有以下错误:

将“const boost::shared_ptr”作为“boost::shared_ptr<>”和“boost::shared_ptr<>:”操作符的“this”参数传递= (const boost::shared_ptr&)[Y=const continuous::continuous_set,T=continuous::continuous_set]丢弃限定符


有人能帮我找出原因吗?

常量中的成员函数吗

如果我正确地阅读了您的代码,那么您正在尝试将类的成员从const member函数更改为不允许的成员。从成员函数中删除
常量
,或使成员
可变

所以

可变邮政编码参数my\u post;

不过,我会注意这个方法。也许可以重新评估为什么正在更改的方法是
my_post
。它不应该是
const
,也不应该更改
my_post

您正试图根据错误消息分配给
const
指针:“将'const boost::shared_ptr'作为'this'参数传递”

您提到的成员函数肯定是
const
,因此出现了错误


<>你应该重新考虑你的设计,而不是在代码中到处乱扔<代码>易变的< /代码>。

把我的2分钱扔掉,这不是我所认为的“好”的地方使用<代码>易变的< /代码>。
my_postc.initial_set_ptr = my_postc.initial_set_ptr->transform(some_obj);
boost::shared_ptr<continuous_set>
mutable postc_params<scalar_type> my_postc;