这里的基本思想是:
const QString ClassName::ALARM_WARNING_IMAGE = "warning.png";
标题:在源文件中写
struct myclass{
//myclass() : x(2){} // Not OK for both x and d
//myclass(){x = 2;} // Not OK for both x and d
static const int x = 2; // OK, but definition still required in namespace scope
// static integral data members only can be initialized
// in class definition
static const double d; // declaration, needs definition in namespace scope,
// as double is not an integral type, and so is
// QSTRING.
//static const QString var; // non integral type
};
const int myclass::x; // definition
const double myclass::d = 2.2; // OK, definition
// const QString myclass::var = "some.png";
int main(){
}
注释'var'的任何理由?这似乎意味着它在什么时候无效。 – 2010-09-13 09:32:20
@Mike Seymour:因为我没有QString定义。 – Chubsdad 2010-09-13 12:42:18