小编use*_*771的帖子

C++奇怪的构造函数行为

任何人都可以向我解释一下Complex a之间的区别; 复合b();

#include<iostream>

class Complex
{
public:

    Complex()
    {
        std::cout << "Complex Constructor 1" << std::endl;
    }

    Complex(float re, float im)
    {
        std::cout << "Complex Constructor 2" << std::endl;
    }

    ~Complex()
    {
        std::cout << "Complex Destructor" << std::endl;
    }    
};

int main()
{
    Complex a;
    std::cout << "--------------------------" << std::endl;
    Complex b();
    std::cout << "--------------------------" << std::endl;
    Complex c(0,0);
    std::cout << "--------------------------" << std::endl;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

Complex Constructor 1
--------------------------
--------------------------
Complex …
Run Code Online (Sandbox Code Playgroud)

c++ stack constructor destructor

5
推荐指数
1
解决办法
219
查看次数

标签 统计

c++ ×1

constructor ×1

destructor ×1

stack ×1