C
case2005
Can anyone help with the following, I don't know if it's possible, but I'm
certain there must be a standard way of dealing with this.
I have the following:
template<typename FooBar, typename Foo>
class Bar {
private:
Foo foo;
}
Now I want to be able to handle when 'Foo' is a primitive type, or more
specifically a primitive pointer type, like 'char *' and also when Foo is
itself a template class:
template<typename FooBar, template<T> class Foo>
class Bar {
private:
Foo<FooBar> foo;
}
All the member functions and other fields of Bar are common to both
template classes. Can I do this with template specialization, if so how, I
don't quite get it.
I also tried to achieve this with the following, which isn't ideal,
because the client of the template must be aware that primitive types
must be wrapped in 'PrimitiveType':
template<class T>
struct PrimitiveType
{
typedef T Type;
};
template<class T>
class WrappedClass
{
public:
typedef WrappedClass<T> Type;
private:
};
template<class FooBar, template<class T> class Foo>
class Bar {
public:
Foo<FooBar>::Type wibble;
};
In theory, 'Bar' can have it's template parameter 'Foo' specified as
either 'PrimitiveType' or 'WrappedClass'.
Alas compilation with g++ simply gives me:
error: syntax error before `;' token
for the line Foo<FooBar>::Type wibble;
I greatly appreciate any light shed on either of these issues.
Many thanks
certain there must be a standard way of dealing with this.
I have the following:
template<typename FooBar, typename Foo>
class Bar {
private:
Foo foo;
}
Now I want to be able to handle when 'Foo' is a primitive type, or more
specifically a primitive pointer type, like 'char *' and also when Foo is
itself a template class:
template<typename FooBar, template<T> class Foo>
class Bar {
private:
Foo<FooBar> foo;
}
All the member functions and other fields of Bar are common to both
template classes. Can I do this with template specialization, if so how, I
don't quite get it.
I also tried to achieve this with the following, which isn't ideal,
because the client of the template must be aware that primitive types
must be wrapped in 'PrimitiveType':
template<class T>
struct PrimitiveType
{
typedef T Type;
};
template<class T>
class WrappedClass
{
public:
typedef WrappedClass<T> Type;
private:
};
template<class FooBar, template<class T> class Foo>
class Bar {
public:
Foo<FooBar>::Type wibble;
};
In theory, 'Bar' can have it's template parameter 'Foo' specified as
either 'PrimitiveType' or 'WrappedClass'.
Alas compilation with g++ simply gives me:
error: syntax error before `;' token
for the line Foo<FooBar>::Type wibble;
I greatly appreciate any light shed on either of these issues.
Many thanks