当前位置:网站首页>22.【【静态成员访问格式】类名::访问成员,则该成员需要是静态】
22.【【静态成员访问格式】类名::访问成员,则该成员需要是静态】
2022-07-21 05:05:00 【李在奋斗……】
【静态成员可用】
#include <iostream>
using namespace std;
class Student
{
public:
int age;
int number;
Student(int a, int nu) :age(a), number(nu) {}
Student() {}
void set()
{
cout << "请输入学生的年龄和学号" << endl;
cin >> age >> number;
}
static void show()
{
cout << "学生的年龄为:" << " " << "学号为:" << endl;
}
};
int main()
{
Student::show();
return 0;
}
【非静态不可用】
#include <iostream>
using namespace std;
class Student
{
public:
int age;
int number;
Student(int a, int nu) :age(a), number(nu) {}
Student() {}
void set()
{
cout << "请输入学生的年龄和学号" << endl;
cin >> age >> number;
}
static void show()
{
cout << "学生的年龄为:" << " " << "学号为:" << endl;
}
};
int main()
{
Student::set();
return 0;
}
边栏推荐
猜你喜欢
随机推荐
Account class
Es aggregate statistical syntax
小游戏类项目 —— 扫雷
Simply recognize deep copy and shallow copy
无法从“boost::shared_ptr<pcl::RangeImage>”转换为“const std::shared_ptr<const pcl::PointCloud<pcl::PointWit
深度理解指针(冒泡排序模拟实现qsort,函数指针实现回调函数)
C. Doremy‘s IQ
Overview of Bert principle
25.【判断是否是素数的方法】
Hetai ht32 & taojingchi tjc--t0 serial port screen learning notes
(好数对)一个数组的值赋给另一个数组
三子棋
Those pits in distributed transactions
Doing questions leads to the understanding of getchar ()
Detailed explanation of scanf - scanf usage you don't know
PCL学习第九章《采样一致性》
Yum install GCC error
Codeforces-479A
Pre training and fine tuning of Google Bert model for beginners
深度剖析 —— 递归