c++如何初始化对象?下面的情况是这样做两次吗
How does c++ initialize an object? Is the following case doing that twice?
假设以下构造函数:
class Needed
{
public:
Needed () {}
Needed (const char *name) {}
};
class Dummy
{
public:
Dummy (): needed ( "Jimmy" ) {}
private:
Needed needed;
};
那么,我在这里初始化needed
两次了吗?
否您在成员初始化程序列表中只初始化过一次。
否,每个Dummy
实例只初始化一次。您刚刚为其初始化提供了参数(并选择了要使用的构造函数)。
相关文章:
- g++的分段错误(在NaN上使用to_string两次时)
- 为什么C++的文件 I/O 在读取文本文件时忽略初始空行?我怎样才能让它不这样做?
- 为什么在C++中对链表这样做?(像堆叠一样处理它们)
- 蛇在C++不会连续转两次
- 检查一个数组是否包含在另一个数组中,以相反的顺序,至少两次
- 从具有按值捕获的 lambda 移动构造 std::函数时,移动构造函数调用两次
- 我应该如何去缓解两次出现的cin?
- Realloc 两次无法在 Visual Studio 上运行
- C++ 如果在 if 为 true 之后运行,为什么还会这样做
- 使用 getline(cin, var) 两次在进行字符串比较时会产生错误 (==)
- 为什么映射插入和 map.find() 的单次迭代比插入和 map.find() 的两次单独迭代慢得多
- C++析构函数调用两次,堆栈分配的复合对象
- 做 std::用相同的unique_ptr移动两次
- 我用C++做了一个计算器,但我对"type of calculator"的要求循环了两次。有人可以帮助指出我的错误吗?
- 做 同时循环重复 cout 线 每循环两次
- C++ cout 打印两次在循环中做
- 虽然我只做过一次LoadLibrary,但我必须做两次FreeLibrary.此外,在卸载DLL后,当试图再次加载它时,
- 成语,在C++做两次某事
- 做..while() 将最后一个字符串重复两次
- c++如何初始化对象?下面的情况是这样做两次吗