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;