我正在用C++编写Apache模块。我需要将所有孩子需要阅读的共同数据存储为共享内存的一部分。结构是一种向量图,所以我想使用STL图和向量。我写了一个共享分配,并为宗旨共享经理,他们工作的优良载体,但没有地图,下面是例子:共享内存STL地图
typedef vector<CustomersData, SharedAllocator<CustomersData> > CustomerVector;
CustomerVector spData; //this one works fine
typedef SharedAllocator< pair< const int, CustomerVector > > PairAllocator;
typedef map<int, CustomerVector, less<int>, PairAllocator > SharedMap;
SharedMap spIndex; //this one doesn't work<
我得到编译时错误,当我尝试使用第二个对象( spIndex),这是成才,如:
../SpatialIndex.h:97: error: '((SpatialIndex*)this)->SpatialIndex::spIndex' does not have class type
它看起来像编译器不能确定SharedMap模板类型,这在我看来是奇怪的一类,在我看来,所有的模板参数被指定。
你能帮忙吗?
感谢 韦努托
您好,感谢您的意见。
SpatialIndex是包含容器的类,它基本上由容器(SharedMap spIndex;它是SpatialIndex的成员)创建,以及两个方法update和getData。
Whithin update方法下面的代码行给出了编译器错误上面:
int spKey = this->calculateSpKey(customer.getLat(), customer.getLong());
this->spIndex[spKey].push_back(customer);
改变最后一行的sintax不同编译器给出了错误,但基本上它说,它无法了解哪些类型变量spIndex是,或者它无法为此类找到适当的重载构造函数。
欢迎。请通过缩进4个空格或1个选项卡来格式化您的代码。 – kennytm 2010-04-01 14:50:51
'SpatialIndex'类型是什么样的?这是否在另一个类中声明了这些内容? – Thomas 2010-04-01 15:01:39
'(SpatialIndex *)这是一个糟糕的主意。如果你绝对需要演员阵容(为什么,我不知道),请使用'static_cast'来确保你不会意外地执行'reinterpret_cast'或意外删除一个const限定符。 – 2010-04-01 18:27:26