小编use*_*270的帖子

什么时候没有调用c ++构造函数?

我有一种情况,似乎没有调用构造函数:

#include <iostream>

using namespace std;

int main ()
{
    class yoyo
    {
        public:
        int i;
        yoyo()
        {
            i = 0;
            cout << "defaultly initialized to 0" << endl;
        }
        yoyo (int j) : i(j)
        {
            cout << "initialized to " << j << endl;
        }
    };

    int i;

    yoyo a;
    cout << "Hello1, i: " << a.i << endl;

    yoyo b(5);
    cout << "Hello2, i: " << b.i << endl;

    yoyo c = b;                                   /* 1 */
    cout << …
Run Code Online (Sandbox Code Playgroud)

c++ constructor explicit-constructor

6
推荐指数
2
解决办法
482
查看次数

标签 统计

c++ ×1

constructor ×1

explicit-constructor ×1