类和结构体
// ConsoleApplication1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 // #include <stdio.h> #include <iostream> #include <string.h> #include <vector> using namespace std; struct lxq1 { double xx = 0; double yy = 0; double zz = 0; double radius = 0; }; class lxq { public: double xx = 0; double yy = 0; double zz = 0; double radius = 0; void show(); void show(lxq1); }; void lxq::show() { cout << xx << "\n" << yy << "\n" << zz << "\n" << radius <<endl; } void lxq::show(lxq1 a) { cout << a.xx << "\n" << a.yy << "\n" << a.zz << "\n" << a.radius << endl; } int main() { lxq a;//类 vector<lxq>sc_v; //类容器 a.xx = 11.1; a.yy = 22.2; a.zz = 33.3; a.radius = 44.4; sc_v.push_back(a); sc_v[0].show(); lxq1 b;//定义结构体 b.xx = 1.0; b.yy = 2.0; b.zz = 3.0; b.radius = 4.0; vector<lxq1>c_v;//结构体容器 c_v.push_back(b); a.show(c_v[0]); system("pause"); return 0; }
运行结果:
11.1
22.2
33.3
44.4
1
2
3
4
请按任意键继续. . .