#include<iostream>// 示例1:静态局部变量voidcountCalls(){// 静态局部变量,只在第一次调用时初始化,之后保持持久性staticint count =0;count++;std::cout <<"Function has been called "<< count <<" times."<< std::endl;}// 示例2:静态全局变量staticint globalVar =42;// 示例3:静态成员变量和静态成员函数classMyClass{public:staticint staticVar;// 静态成员变量staticvoidstaticFunction(){std::cout <<"This is a static member function."<< std::endl;}};int MyClass::staticVar =0;// 初始化静态成员变量intmain(){// 示例1:静态局部变量countCalls();countCalls();countCalls();// 示例2:静态全局变量std::cout <<"Global variable: "<< globalVar << std::endl;// 示例3:静态成员变量和静态成员函数MyClass obj1;MyClass obj2;obj1.staticVar =1;obj2.staticVar =3;std::cout <<"obj1.staticVar: "<< obj1.staticVar << std::endl;std::cout <<"obj2.staticVar: "<< obj2.staticVar << std::endl;// 静态成员变量可通过类名直接访问std::cout <<"MyClass::staticVar: "<< MyClass::staticVar << std::endl;// 调用静态成员函数MyClass::staticFunction();return0;}
输出结果:
Function has been called 1 times.
Function has been called 2 times.
Function has been called 3 times.
Global variable: 42
obj1.staticVar: 3
obj2.staticVar: 3
MyClass::staticVar: 3
This is a static member function.
rk3568 MDIO总线
MDIO(Management Data Input/Output)是一种管理数据输入/输出协议,用于在以太网交换机和PHY(物理层收发器)之间进行通信。在网络设备中,MDIO总线用于控制网络接口的PHY芯片,例如通过MDIO总线访问PHY芯片的寄存器。这些寄存器包含了一些关于网络连接状态…