• Advertisement
Sign in to follow this  

Dreaded template errors are killing me!

This topic is 4722 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am having trouble with these two little template specializations. I'm running on Intel's 8.1 C++ compiler because MS VC 7.1 won't even compile the rest of this library. Hopefully this is a gernal enough C++ template specialization issue that non Intel users can take a look at this. The two offending pieces of code are the last two template specializations at the end of the code segment below, and part of the macro called SQUADD_DEFINE_CLASS_LOCATION_IN_REGISTRY: I'm praying someone can help solve this as I've spent several weeks looking for a solution.
template <class Class>
struct push_class_from_registry
{
	inline static void onto(HSQUIRRELVM v) 
	{	
	}
	
	static const char * table;
	static const char * name;
};
template<class Class> const char * push_class_from_registry<Class>::table = NULL;

template<class Class>
struct store_in_registry
{
	inline static void perform(HSQUIRRELVM v)
	{
	}
};

#define SQUADD_DEFINE_CLASS_LOCATION_IN_REGISTRY(Class, Table, Index) 
template<> class pushclass< Class > : public push_class_from_registry< Class > {}; 
template<> const char * push_class_from_registry< Class >::table = Table; 
template<> const char * push_class_from_registry< Class >::name = Index;

By the way, this modification doesn't work either:

#define SQUADD_DEFINE_CLASS_LOCATION_IN_REGISTRY(Class, Table, Index) 
template<> class pushclass< Class > : public push_class_from_registry< Class > {}; 
template<> const char * push_class_from_registry< Class >::table = Table; 
template<> const char * push_class_from_registry< Class >::name = Index;

Share this post


Link to post
Share on other sites
Advertisement
Uhm, template support MSVC .NET 2003 (aka 7.1) is more standards conformant than Intel C++ 8.1. And what you're doing is pretty basic stuff, don't see why it should even require templates.

Did you leave it out or is there no general "pushclass" template ?
Because you can't specialize a class for which no generic template is available (even an empty one would suffice).

-Markus-

Share this post


Link to post
Share on other sites
I'm not fully sure what you're trying to accomplish, but here's a slightly modified version which performs what I think you want :)


#include <iostream>

typedef unsigned long HSQUIRRELVM;

template<class Class>
struct push_class_from_registry {
static void onto(HSQUIRRELVM v) {}
static const char *table;
static const char *name;
};
template<class Class> const char *push_class_from_registry<Class>::table = NULL;
template<class Class> const char *push_class_from_registry<Class>::name = NULL;

#define SQUADD_DEFINE_CLASS_LOCATION_IN_REGISTRY(Class, Table, Index) \
template<> void push_class_from_registry<Class>::onto(HSQUIRRELVM v) {} \
template<> const char *push_class_from_registry<Class>::table = Table; \
template<> const char *push_class_from_registry<Class>::name = Index;

// ------------------------------------------------------------

class Test {};
SQUADD_DEFINE_CLASS_LOCATION_IN_REGISTRY(Test, "Mooh", "Test");

int main() {
std::cout << push_class_from_registry<Test>::name;
}



-Markus-

Share this post


Link to post
Share on other sites
Quote:
Original post by Cygon
Did you leave it out or is there no general "pushclass" template ?
Because you can't specialize a class for which no generic template is available (even an empty one would suffice).

A generic definition is not required in order to specialize a template. All you need is a declaration, although he doesn't show that either.

Share this post


Link to post
Share on other sites
Quote:
Original post by Cygon
Uhm, template support MSVC .NET 2003 (aka 7.1) is more standards conformant than Intel C++ 8.1. And what you're doing is pretty basic stuff, don't see why it should even require templates.

Did you leave it out or is there no general "pushclass" template ?
Because you can't specialize a class for which no generic template is available (even an empty one would suffice).

-Markus-


I left out the pushclass template.

And secondly, this is from a library that I did not write.

I am not aware that 7.1 is more standard compliant when it comes to templates. I had heard differently from Intel, but maybe they are blowing smoke in my face.

Share this post


Link to post
Share on other sites
As noted, the backslashes are required at the ends of lines of the #define; as is, the next few lines stand on their own and are not part of the macro. Thus your #defines expand to nothing, and you have these weird template specializations for an unknown class "Class".

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement