views:

299

answers:

2

Hello, I am writing an Apache module in C++. I need to store the common data that all childs need to read as a portion of shared memory. Structure is kind of map of vectors, so I want to use STL map and vectors for it. I have written a shared allocator and a shared manager for the purpose, they work fine for vectors but not for maps, below is the example:

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<

I get compile time errors when I try to use the second object (spIndex), which are someting like:

../SpatialIndex.h:97: error: '((SpatialIndex*)this)->SpatialIndex::spIndex' does not have class type

It looks like the compiler cannot determine a type for SharedMap template type, which is strange in my opinion, it seems to me that all the template parameters have been specified.

Can you help?

Thanks Benvenuto

Hello, thanks for your comments.

SpatialIndex is the class that contains the container, it basically made by the container (SharedMap spIndex; which is a member of SpatialIndex), and two methods, update and getData.

Whithin the update method the following line of code gives the compiler error above:

int spKey = this->calculateSpKey( customer.getLat(), customer.getLong() );
this->spIndex[spKey].push_back(customer);

Varying the sintax of the last line varies the error the compiler gives, but basically it says that it cannot understand which type variable spIndex is, or that it cannot find the appropriate overload constructor for this class.

A: 

Please post the line on which you initialize spIndex. The compiler error 'does not have class type' generally means that you're referring to a function as though it were a field, which in this case probably means that your compiler has mistaken spIndex for a function somehow. I haven't seen the code, but I bet the Most Vexing Parse is going to come up somehow.

David Seiler
A: 

Hello, thanks very much for the help, initialization line was indeed

SharedMap spIndex( less<int>(), PairAllocator );

which was interpreted by the compiler as function that takes two parameters and returns a SharedMap object, thus leading to all the problems above. Changing this line to:

SharedMap spIndex;

Lead to a more intelegible error, kind of 'cannot find an appropriate constructor for that stl_tree object that internally manages the stl::map'.

This other error was solved deleting the 'explicit' word from the following lines in SharedAllocator.h

inline explicit SharedAllocator(SharedAllocator const&) {}

template<typename U>
inline explicit SharedAllocator(SharedAllocator<U> const&) {}

which I was wrong considering it just boilerplate code...