标签:std names ble c++ 拷贝 return turn pre public
一、构造函数分类
普通构造函数,复制(拷贝)构造函数,赋值构造函数,
#include <iostream> using namespace std; class A { public: A() { a = 0; }//普通 A(const A&other) {//复制 this->a = other.a; } A &operator=(const A & other) {//赋值 this->a = other.a; return *this; } A(double convert) {//转换构造函数 this->a = int(convert); } private: int a; }; int main() { A a, b;//调用普通构造函数 A c = b;//调用复制构造函数 c = a;//调用赋值构造函数 A d(c);//调用赋值构造函数 double e = 0.1; A f(e); return 0; }
标签:std names ble c++ 拷贝 return turn pre public
原文地址:http://www.cnblogs.com/MyBlog-Richard/p/5994956.html