C++构造函数基础
#include <iostream>#include <string>
#include <vector>
using namespace std;
int main(void)
{
//构造函数
struct block
{
block(void) = default;
block(int data_1, int data_2) : data_1(data_1), data_2(data_2) {}
int data_1;
int data_2;
void show(void)
{
cout << this->data_1 << "" << this->data_2 << endl;
}
};
//定义一个类对象
struct block aclass(1, 2);
aclass.show();
return 0;
}
文档来源:51CTO技术博客https://blog.51cto.com/u_15302296/3072246
页:
[1]