woaidongmao

文章均收录自他人博客,但不喜标题前加-[转贴],因其丑陋,见谅!~
随笔 - 1469, 文章 - 0, 评论 - 661, 引用 - 0
数据加载中……

赋值operator=的错误定义记录

//----发生了自身调用自身的错误

struct ToleranceOverrideExc
{
    ToleranceOverride rule_data;
    set<SymbolTolerancePoint> symbol_points;
    ToleranceOverrideExc(){memset(&rule_data, 0, sizeof(ToleranceOverride));}
    ToleranceOverrideExc(const ToleranceOverride& tol_ovr){rule_data= tol_ovr;}
    ToleranceOverrideExc(const ToleranceOverrideExc& other){*this= other;}
   ToleranceOverrideExc& operator=(const ToleranceOverrideExc& other){*this= other;return *this;}
    operator ToleranceOverride(){return rule_data;}
    void SetValue(ToleranceOverride& save){rule_data= save;symbol_points.clear();}
};

 

备忘:

struct POD,的默认operator=可以保证其内部:子成员是POD会memcpy,子成员非POD会调用operator=

posted on 2008-11-06 15:24 肥仔 阅读(184) 评论(0)  编辑 收藏 引用 所属分类: C++ 基础


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理