本文共 565 字,大约阅读时间需要 1 分钟。
cglobal.h
#ifndef CGLOBAL_H#define CGLOBAL_Hextern int testValue;#endif // CGLOBAL_H
cglobal.cpp
#include "cglobal.h"int testValue = 1;
调用方式
#include "cglobal.h"qDebug() << testValue; testValue = 2;
cglobal.h
#ifndef CGLOBAL_H#define CGLOBAL_Hclass CGlobal {public: CGlobal(); ~CGlobal();public: static int testValue;};#endif // CGLOBAL_H cglobal.cpp
#include "cglobal.h"CGlobal::CGlobal() {}CGlobal::~CGlobal() {}int CGlobal::testValue = 1; 调用方式
#include "cglobal.h"qDebug() << CGlobal::testValue; CGlobal::testValue = 2;
建议使用第二种方式
转载地址:http://bbysz.baihongyu.com/