whats wrong with this code? (template class) - corrected

A

Anonymous

I have been trying to write a template class for a shared memory
container, over the last few days - but I keep getting numerous compiler
errors e.g:


Error: syntax error : identifier 'myStaticShmemAllocator<void>'
Error: 'AllocationPolicy' : undeclared identifier


Here is the truncated code below -

// template Header file
extern shared_memory static_shmem;
extern shared_memory dyn_shmem;


template <class T>
struct myStaticShmemAllocator
{
static T* Allocate(const size_t blocksize, const bool zeroed=true)
{
return static_shmem.allocate(blocksize, zeroed);
}

static void DeAllocate(T *ptr)
{
if(ptr);
static_shmem.free(ptr) ;
}
};



template <class T>
struct myDynamicShmemAllocator
{
static T* Allocate(const size_t blocksize, const bool zeroed=true)
{
return dyn_shmem.allocate(blocksize, zeroed);
}

static void DeAllocate(T *ptr)
{
if(ptr);
dyn_shmem.free(ptr) ;
}
};



template <class ValueType, template <class SharedMemoryType> class
AllocationPolicy= myStaticShmemAllocator<void> >
class myShmemHashTable
{
//Impl
};


//////// Code to test templates
struct MyStruct { int x; int y;};

int main(int argc, char* argv[])
{
//implicit creation in static shmem (using dflt tplt arg)
myShmemHashTable<MyStruct> a_static ;

//explicit creation in static shmem
myShmemHashTable<MyStruct, myStaticShmemAllocator<void> > a1_static ;

//explicit creation in dynamic shmem
myShmemHashTable<MyStruct, myDynamicShmemAllocator<void> > a_dynamic;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top