storage-solution.cpp
来自「压缩包里有教材<<C++模式设计-基于QT4开源跨平台开发框架>」· C++ 代码 · 共 46 行
CPP
46 行
#include <qstd.h>using namespace qstd;int i; /* Global / Static */static int j; /* File / Static */extern int k; /* Global / Static */ const int l=10; /* This is a file scope variable, but it mightnot be stored anywhere, since it is easily optimized out by thecompiler. */extern const int m=20; /* Global / static */class Point /* Global scope, but no storage class, since it is not an object */{ public: QString name; /* class / various - all class scope variables have various storage class, since it depends on how the containing objects were created. */ QString toString() const; private: static int count; int x, y; /* class / various */};int Point::count = 0; /* Point::count has global scope, butcount by itself has class scope inside class Point. The object has static storage class. */QString Point::toString() const { return QString("(%1,%2)").arg(x).arg(y); /* class / various */}int main(int argc, char** argv) /* block / stack */{ int j; /* block / stack */ register int d; int* ip = 0; /* block / stack */ ip = new int(4); /* no scope / heap - the object created has no identifier, so it has no scope. However, it is in the heap storage class. */ Point p; /* block / stack */ Point* p2 = new Point(); /* no scope / heap */}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?