1 #include <iostream>
2 using namespace std;
3
4 struct point
5 {
6 int a;
7 int b;
8 };
9
10 class myclass
11 {
12 public:
13 int x;
14 int y;
15 myclass(
int n):x(n),y(n)
16 {
17
18 }
19 //构造类型转换,传递point结构体进行初始化
20 myclass(
const point &
p) :x(p.a), y(p.b)
21 {
22
23 }
24 };
25
26 void main()
27 {
28 myclass my(
5);
29 myclass my1 =
5;
//把5转换为myclass类型
30
31 point p{
1,
2 };
32 myclass my2(p);
33 myclass my3 =
p;
34 cin.
get();
35 }
转载于:https://www.cnblogs.com/xiaochi/p/8593468.html
转载请注明原文地址: https://win8.8miu.com/read-26692.html