#ifndef TESTSTATIC_H
#define TESTSTATIC_H
#include<QObject>
#include<QDebug>
class TestStatic:public QObject
{
public:
TestStatic();
void testhello(){
qDebug()<<
"hello static";
}
static int number;
};
int TestStatic::number=
100;
static int Testhe(){
return TestStatic::number;
}
#endif // TESTSTATIC_H
在其他文件中,可以直接调用静态方法,无需要加类名+前缀
int main(
int argc,
char *argv[]){
qDebug()<<Testhe();
}
静态方法中不能调用非静态属性