只能用于构造函数的explicit

这个关键字只能用于构造函数,意思是该构造函数不能隐式的被调用。函数 当有隐式的类型转换的时候,该explicit能够阻止这一过程。code 如:ci class One{ public: One(){} }; class Two{ public: Two(const One&){} }; void f(Two){} int main(){ One one; f(one); } 该程序可以运行
相关文章
相关标签/搜索