A
Alexander Stippler
Hello,
I want to write a non-template class with a constructor template member.
The constructor shall not take arguments. Is this possible at all?
Here the concrete example: A class which contains three vectors. There
are several different methods to initialize these vectors(size and
contents). These methods are the template parameter I want to use.
enum Method {A, B, C, D, E, F};
class Butcher
{
public:
template <Method m>
Butcher();
private:
Vector a, b, c;
};
template <>
Butcher::Butcher<A>()
: a(2), b(4), c(2)
{
a = 0.5, 1;
b = -1, 1, 3, 2;
c = 0, 1;
}
....
I do not want to call a template function from a normal constructor because
I would have to allocate the vectors twice. Is there a way. I think the
trouble is that constructors are unnamed and I have no argument, from which
the template parameter value can be derived.
regards,
alex
I want to write a non-template class with a constructor template member.
The constructor shall not take arguments. Is this possible at all?
Here the concrete example: A class which contains three vectors. There
are several different methods to initialize these vectors(size and
contents). These methods are the template parameter I want to use.
enum Method {A, B, C, D, E, F};
class Butcher
{
public:
template <Method m>
Butcher();
private:
Vector a, b, c;
};
template <>
Butcher::Butcher<A>()
: a(2), b(4), c(2)
{
a = 0.5, 1;
b = -1, 1, 3, 2;
c = 0, 1;
}
....
I do not want to call a template function from a normal constructor because
I would have to allocate the vectors twice. Is there a way. I think the
trouble is that constructors are unnamed and I have no argument, from which
the template parameter value can be derived.
regards,
alex