类的赋值运算符和拷贝构造函数

#include<stdio.h>

class A
{
  private:
    const A& operator=(const A&);
};

int main()
{
  A a;
  A b = a;//ok,实际上是A b(a),即调用拷贝构造函数
  A c;
  c = a;//error,因为'='已被声明为私有
  return 0;
}

 

posted @ 2014-09-02 20:03  米其林轮船  阅读(157)  评论(0编辑  收藏  举报