473,324 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

What is wrong with this code ? (template class)

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 SharedMemoryTypeclass
AllocationPolicy= myStaticShmemAllocator<void
class static_shmemHashTable
{
//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<MyStructa_static ;

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

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

Sep 3 '07 #1
1 1481
On Sep 3, 1:19 pm, Anonymous <no.re...@here.comwrote:
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 SharedMemoryTypeclass
AllocationPolicy= myStaticShmemAllocator<void
class static_shmemHashTable
{
//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<MyStructa_static ;

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

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

}- Hide quoted text -

- Show quoted text -
IMHO
template <class ValueType, template <class SharedMemoryTypeclass
AllocationPolicy= myStaticShmemAllocator<void
class static_shmemHashTable
this should become

template <class ValueType, template <class SharedMemoryTypeclass
AllocationPolicy= myStaticShmemAllocator >
class static_shmemHashTable

since it's a template< typename class you should not specifiy the
templated typename or else you're giving a precise type not a
templated class

also the code down below should be stripped of <voidafter
myStaticShmemAllocator and myDynamicShmemAllocator

Hope it helps.
FB

Sep 3 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

52
by: Tony Marston | last post by:
Several months ago I started a thread with the title "What is/is not considered to be good OO programming" which started a long and interesting discussion. I have condensed the arguments into a...
2
by: Rafal Dabrowa | last post by:
I try to write template class specialization. I wrote the following code: template<class T> class A { public: A(); }; template<> class A<char> { public:
4
by: | last post by:
I have these errors with code following: --------------------------------------------------------------- 'SharedObject' : use of class template requires template argument list...
2
by: marco | last post by:
the problem: I use a typedef inside a class template, than I use this type (dim_v<N1>::Type) to define the argument of a template function f but when I call this function from main, the compiler...
72
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
1
by: Tony Johansson | last post by:
This class template and main works perfectly fine. But could be better. I have this class template called Handle that has a pointer declared as T* body; As you can see I have a reference counter...
11
by: Micha | last post by:
Hello there, I think I've run into some classic c++ pitfall and maybe some of you guys can help me out. For my project I will need to use matrices and vectors and so I decided to implement them...
7
by: mosfet | last post by:
HI, when trying to compile an embedded version of STL called ustl on win32 platform I get the following error : /// Returns the minimum of \p a and \p b template <typename T1, typename T2>...
32
by: Stephen Horne | last post by:
I've been using Visual C++ 2003 for some time, and recently started working on making my code compile in GCC and MinGW. I hit on lots of unexpected problems which boil down to the same template...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.