码迷,mamicode.com
首页 > 其他好文 > 详细

explicit关键字

时间:2016-03-19 16:22:28      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:

#include <iostream>

using namespace std;

class TestClass{

public:
    TestClass(){
        cout << "constructor" << endl;
    }
    TestClass(int a){
        cout << "constructor " << a << endl;
    }
};

class TestClass2{
public:
    TestClass2(){
        cout << "constructor" << endl;
    }
    explicit TestClass2(int a){
        cout << "constructor " << a << endl;
    }

};


int main(){
    TestClass t;
    TestClass t1 = 6;

    TestClass2 t2;
    TestClass2 t2 = 7;//编译通不过了~~~

    cout << "letben" << endl;
    system("pause");
}

参见:

http://baike.baidu.com/link?url=ZdpF1NVfUtlRZHDNbN3RWRjBDzkOSzMWojBJs7RAqVkzVKr8qCC62DhY2FoA7MqopOnG3L13Pi3eARBCLC_QLK

explicit关键字

标签:

原文地址:http://www.cnblogs.com/letben/p/5295214.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!