枚舉、隨機數
#include <iostream>
#include <random>
#include <time.h>
using namespace std;
int main()
{
int colo;
enum Color {red,yellow,green};//聲明枚舉類型
//Color pri;//定義Color類型變量pri
int pri;
//隨機取值
uniform_int_distribution<unsigned> u(0, 2);
default_random_engine e(time(0));
//cout << e << endl;
for (size_t i = 0; i < 18; i++)
{
pri = u(e);
switch (pri)
{
case red:
cout << "red" << endl;
break;
case yellow:
cout << "yellow" << endl;
break;
case green:
cout << "green" << endl;
break;
default:
break;
}
}
system("pause");
return 0;
}
嵌套類
#include <iostream>
using namespace std;
class c1
{
public:
int a;
void foo();
class c2
{
public:
int a;
void foo();
} b;
};
void c1::foo()
{
a = 1;
}
void c1::c2::foo()
{
a = 2;
}
int main()
{
class c1 f;
f.foo();
f.b.foo();
cout << f.a << endl;
cout << f.b.a << endl;
system("pause");
return 0;
}
局部類
#include <iostream>
using namespace std;
void fun()
{
class MyClass
{
public:
void fun1()
{
cout << "局部類調用成功" << endl;
}
};
MyClass str;
str.fun1();
}
int main()
{
fun();
system("pause");
}
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。