Mixture

身未动,心已远

导航

2014年4月7日 #

codility: Euclidean algorithm ( ChocolatesByNumbers, CommonPrimeDivisors)

摘要: Chocolates By NumbersTwo positive integers N and M are given. Integer N represents the number of chocolates arranged in a circle, numbered from 0 to N... 阅读全文

posted @ 2014-04-07 10:10 parapax 阅读(1518) 评论(0) 推荐(0) 编辑

effective c++ 11: Handle assignment to self in operator =

摘要: 比如有这样一个class:class A {};class B { ...private: A* a;};在写class B的赋值函数的时候,假如写成下面这样:B& B::operator=(const B& rhs) { delete a; a = new A(*rhs.a); return *this;}假如是自我赋值,那上面这个代码显然就不对了,*this和rhs是一个对象,所以如果都delete a 了下面还怎么new A(*rhs.a)呢。可以通过identity test检查是否是自我赋值:if(this==&rhs) return *this在上面那... 阅读全文

posted @ 2014-04-07 00:08 parapax 阅读(260) 评论(0) 推荐(0) 编辑