即使我重载 = 运算符,也无法生成赋值运算符
我的类是多态的,无论如何都不应该被用来 ='d。它有一个 Font& 类型的成员。因此编译器无法生成 = 运算符。所以我只是创建了赋值和复制构造函数的虚拟实现,将它们放在类的私有中,但它仍然警告我赋值运算符无法生成。我还能如何摆脱这个警告?
谢谢
警告9警告C4512:'AguiWidget':无法生成赋值运算符c:\ users \ josh \ Documents \ Visual Studio 2008 \ Projects \ agui \ alleg_5 \ agui \ aguiwidget.hpp 250
My class is polymorphic and should not be used to be ='d anyways. It has a member which is of type Font& and as a result the compiler cannot generate an = operator. So I just created dummy implementations of the assignment and copy constructor, put them in the private of the class, but it still warns me about assignment operator not able to get generated. How else can I get rid of this warning?
Thanks
Warning 9 warning C4512: 'AguiWidget' : assignment operator could not be generated c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\agui\aguiwidget.hpp 250
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
编译器警告您的赋值运算符是您自己的类的赋值运算符。您现在拥有的是:
您需要的是:
The assignment operator that the compiler is warning you about is the one for your own class. What you have now is:
What you need is:
您可以禁用它。当然,如果您确实尝试使用这些运算符,那么这是行不通的。
你确定你的签名正确吗?您是否为每个类、基类和派生类制作了它们?
You can disable it. This won't work, of course, if you're actually trying to use those operators.
Are you sure you got the signatures right? Did you make them for each class, base and deriveds?
使用 boost::noncopyable 。
注意:
boost::noncopyable 也将对所有子类强制执行。
编辑:
哇...那是一门可怕的课程...
使用 pimpl idiom 来减少代码相互依赖性并提高界面可读性。
此外,您还应该尝试避免受保护的成员变量(尽可能多),因为它会破坏封装。
Use boost::noncopyable.
NOTE:
boost::noncopyable will be enforced for all sub-classes as well.
EDIT:
Wow... that's one scary class...
Use the pimpl idiom to reduce code interdependencies and improve interface readability.
Also you should try to avoid protected member variables (as much as possible) as it breaks encapsulation.