[url]http://www.devx.com/tips/Tip/5602[/url]
#include <string>
class Buff
{
private:
static const int MAX = 512; //definition
static const char flag = 'a'; //also a defintion
static const std::string msg; //non-integral type; must be defined outside the class body
public:
//..
};
// 放到.cpp文件里为好
const std::string Buff::msg = "hello";
// 在c++语言中,#ifndef的作用域只是在单个文件中。所以如果h文件里定义了全局变量,
// 即使采用#ifndef宏定义,多个c文件包含同一个h文件还是会出现全局变量重定义的错误。