Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Template-Controled Constructor Use without PTS

Status
Not open for further replies.

Wereotter

Programmer
Aug 30, 2004
17
US
I think I've encountered a problem beyond my template metaprogramming skills... :)
Here's the deal: I need to choose a constructor (preferrablly at compile time) based upon an argument to my template.
Code:
class Example1
{
	Example1(int a);
};
class Example2
{
	Example2(int a, bool b);
};

typedef struct{} tagConstructorInt;
typedef struct{} tagConstructorIntBool;

template<class Type, class Tag> class Creator
{
	Type* Create();
};

template<class Type> Type* Creator<Type, tagConstructorInt>::Create()
{
	return new Type(500);
}

template<class Type> Type* Creator<Type, tagConstructorIntBool>::Create()
{
	return new Type(500, true);
}
That pretty much summarizes it. I think that code would work. The catch? I can't use partial template specialization, as my compiler doesn't support it. Is there any way around this?
I do have complete control of all code in question, and thus could modify the design to use member functions to set the additional parameter, for example, but I'd rather not.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top