可以在C ++ Header.h文件中放置非(静态常量整型)类型
||
我在MyClass.h文件中有一个类:
// MyClass.h
#ifndef __MY_CLASS_H__
#define __MY_CLASS_H__
#include <string>
class MyClass
{
static const std::string MyStaticConstString; // I cannot initialize it here, because it\'s not an integral type.
};
// OK, let\'s define/initialize it out side of the class declaration
// static
const std::string MyClass::MyStaticConstString = \"Value of MyStaticConstString\";
#endif
问题是,如果该文件被包含多次,编译器将抱怨“多个定义”。
因此,我必须将ѭ1的定义移至MyClass.cpp文件。但是如果MyClass
是库的一部分,我希望我的用户在MyClass.h文件中看到const静态值,那是有道理的,因为它是静态const值。
我应该怎么做?我希望我能说清楚。
谢谢。
彼得
没有找到相关结果
已邀请:
3 个回复
邵酮
),它们是为实现目的保留的。
献导外拘
诫商
并在源文件中执行此操作:
请记住,带下划线前缀的名称是保留的,请勿使用。使用
。