无法分配指向模板化类的指针的成员
我的问题是,在我的“Widget”类中,我有以下声明:
MouseEvent* X;
在成员函数中,我以正常方式用地址初始化指针:
X = new MouseEvent;
好的,最后一行使编译器停止在:
错误 C2166:左值指定 const 对象
好吧,MouseEvent 被声明为 typedef 以简化事情:
typedef Event__2<void, Widget&, const MouseEventArgs&> MouseEvent;
Event__2 是,正如您可能想象的那样:(显示基本结构):
template <typename return_type, typename arg1_T, typename arg2_T>
class Event__2
{
...
};
我不知道 Event__2 类从哪里获取常量限定符。 有小费吗 ?
谢谢。
My problem is that in my "Widget" class i've the following declaration:
MouseEvent* X;
In a member function I initialize the pointer with an address the normal way:
X = new MouseEvent;
Ok, this last line makes the compiler stop at:
error C2166: l-value specifies const object
All right, a MouseEvent is declared as a typedef to simplify things:
typedef Event__2<void, Widget&, const MouseEventArgs&> MouseEvent;
And Event__2 is, as you may imagine as: (basic structure shown):
template <typename return_type, typename arg1_T, typename arg2_T>
class Event__2
{
...
};
I don't know where the Event__2 class gets the const qualifier. Any tips ?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很可能,您初始化 X 的成员函数被标记为 const - 类似这样。
这里的解决方案是
选择以上其中一项:
Likely, the member function where you are initializing X is marked as const - something like this.
The solution here is either to
mutable
.Pick one of the above: