【发布时间】:2013-07-26 11:15:47
【问题描述】:
我正在创建一个组件,一个模板的泛化。创建时必须使用字符串标识符。
我正在替换:
#define MYCOMPONENT_CONSTANT_IDENTIFIER "ID value"
与
namespace myComponent
{
static const QString constant_identifier = "ID value"
}
遵循一些编码标准(MISRA,...)。
这应该适用于 C++。我在Constants-only header file C++ 进行了检查。
此常量在组件“myComponent”的标题中定义,并包含在初始化我的索引器和创建组件的标题中。这在更换时没有更改。
替换构建成功,但尝试运行失败。 分段错误发生在:
template<>
inline void TMyIndexer::Init()
{
Map(...)
//before
//Map( ENUM_VAL, QSharedPointer<ITableFieldDefs>(new myComponent::TTableFieldDefs(MYCOMPONENT_CONSTANT_IDENTIFIER)) );
Map( ENUM_VAL, QSharedPointer<ITableFieldDefs>(new myComponent::TTableFieldDefs(myComponent::constant_identifier)) );
Map(...)
}
地点:
// TStaticFieldDefs<> implements ITableFieldDefs
typedef TStaticFieldDefs<myComponent::Fields> TTableFieldDefs;
//constructor
TStaticFieldDefs(QString id) : fId(id) {}
如果我上栈:
2.) qstring.h: 内联 QString::QString(const QString &other) : d(other.d) { Q_ASSERT(&other != this); d->ref.ref(); }
1.) qatomic_x86_64.h: inline bool QBasicAtomicInt::ref()
我认为模板泛化、构造函数中的内联定义或其他我不知道的地方有问题。
欢迎任何解释。
我没有想法,恳请帮助。
【问题讨论】:
-
您是否尝试过完全重建?也许也可以通过手动删除任何临时文件夹/文件然后重建?修复了我迄今为止遇到的 90% 的分段错误
-
是的,我做到了。完全清理和重建。我已经更新了描述。
-
我将尝试在一个更微不足道的情况下进行检查。 Timthanx 的回应。
标签: c++ qt templates header constants