c++ - 为什么具有 2 个参数参数的构造函数接受复制对象作为 1 个参数参数?
问题描述
class person
{
std::string name;
int age;
public:
person(const std::string& name, int age) : name(name), age(age)
{
}
};
int main()
{
person a("Bjarne Stroustrup", 60);
person b(a); // What happens here?
b = a; // And here?
}
为什么带有 2 个参数参数的构造函数接受复制对象作为参数。person b(a)
我们用 1 个不同类型的参数调用构造函数,它有效吗?
如何 ?
解决方案
推荐阅读
- asp.net - Asp.net Boilerplate - 没有给出与所需形式参数相对应的参数
- php - 将授权标头传递给用户电子邮件 url
- python - 将 ZipDataSet 写入 TFRecord
- javascript - 无法在本地调试 node.js
- java - Java Date 将分钟和秒设置为 0
- ios - 在 iOS 上隐藏/清除 Stage3D 会隐藏 2D 屏幕内容 - 我怎样才能让它再次渲染 2D?
- reactjs - React-navigation:使用底部选项卡导航器时不显示标题
- c++ - 链表并按字母顺序插入字符串
- python - 每个线程的单独变量
- sql - 在 SQL Server 中更新日期时间的时间部分