【发布时间】:2016-08-29 06:48:51
【问题描述】:
我正在学习如何格式化 C++,所以它是最干净的,但我不知道什么。
如何存储函数特定的常量变量? 我有以下两个想法:
我的第一个想法:
.cpp 内:
// ---------------------------------------------------------
// Purpose: Drawing the menu background.
// ---------------------------------------------------------
inline void DrawBackground() {
static int BeginWidth = 80;
static int EndWidth = 590;
//usage of the BeginWidth and EndWidth
}
我的第二个想法:
.h 内:
const int BeginWidth = 80;
const int EndWidth = 590;
.cpp:
// ---------------------------------------------------------
// Purpose: Drawing the menu background.
// ---------------------------------------------------------
inline void DrawBackground() {
//usage of the BeginWidth and EndWidth
}
这些想法是否正确?如果两者都正确,是否认为其中一个更合适?
【问题讨论】: