Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想创建一个可以被我创建的所有类访问的变量。我该怎么做呢?我尝试在主窗口头文件中声明:
public: extern int number;
然后通过说在其他类中引用它:
MainWindow::number;
这给了我一个错误:错误:为“数字”指定的存储类。谁能说我做错了什么?
成功的关键词是static。使其成为静态变量。
static