本文介绍了C ++量静态成员数组初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有类Foo与是一个dynamic_bitset的一个非常大的数组成员变量吧。我想使变量巴静态的内存起见,我也想它是常量。条的值被存储在predefined文件。我应该在哪里放置code文件进行读取和初始化吧?
I have class Foo with a member variable bar which is a very big array of dynamic_bitset. I would like to make variable bar static for the sake of memory, I would also like it to be const. The value of bar is stored in a predefined file. Where should I put the code for reading the file and initializing bar?
推荐答案
MadScienceDreams的解决方案可能会工作,但你可以更简单地做到这一点:
MadScienceDreams's solution will probably work, but you can do this much more simply:
class A
{
static const vector<dynamic_bitset> s;
public:
// ...
};
在实现文件
vector<dynamic_bitset> LoadBitsets()
{
//...
return something;
}
const vector<dynamic_bitset> A::s(LoadBitsets());
此举构造应该得到自动使用。
The move constructor should get used automatically.
这篇关于C ++量静态成员数组初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!