C++奇淫技巧

一、关于:的妙用

  如下代码

#include<cstdio>
#include<iostream>

typedef struct point{
    int a;
    int b;
    point();
    point(int cc, int bb);
}pp;

point::point():point(1,2) {
}

point::point(int tempa, int tempb):a(tempa),b(tempb) {

}
int main() {
    pp temp;
    pp temp1(23, 24);
    std::cout << "调用默认构造函数" << temp.a << " " << temp.b << std::endl;

    std::cout << "调用非默认构造函数" << temp1.a << " " << temp1.b << std::endl;
    system("pause");
    return 0;
}

通过 :符号实现默认无参构造函数的实现

猜你喜欢

转载自www.cnblogs.com/cutelife/p/11738889.html