1 #include <iostream>
2 using namespace std;
3
4 class myclass
5 {
6 public:
7 int num;
8 int num2;
9
10 public:
11 myclass(int num)
12 {
13 this->num = 0;
14 this->num2 = num;
15 }
16 };
17
18 //后缀定义只能在外部
19 //加后缀的类型只能为char,wchar_t,char16_t或unsigned long long
20 myclass operator "" _cocos_cgw(unsigned long long data)
21 {
22 //返回一个类,在寄存器中生成,调用一个参数的构造函数,大括号给类初始化
23 return { (int)data };
24 }
25
26 void main()
27 {
28 myclass mynum = 12_cocos_cgw;
29 cout << mynum.num << endl;
30 cout << mynum.num2 << endl;
31 cin.get();
32 }