Victor said:
Victor said:
Daniel said:
I have a template:
template<typename t, int foo>
class MyTemplate {
public:
template<typename bar>
MyTemplate() {
bar::something(foo);
}
}
How would I instantiate a local instance of this class?
MyTemplate<SomeType, 3> <SomeBarType>() doesn't seem to work.
Are you trying to create a temporary of that type?
Nor does any other things I've tried.
You can't. A template[d] constructor has to have an argument from
which the compiler will deduce the template argument. In your case
you probably want to create a "factory method":
template<class bar> MyTemplate from() {
Should probably be
template said:
MyTemplate retval;
bar::something(foo);
return retval;
}
BTW, how would you use it?
V
V
I basically am trying to create a return value. I'm trying to create a
generic way to apply a binary operation to the components of two
Vectors, and return a third Vector with the results.
If you've seen my other recent posts, you might gather that Vector is a
creation of my own. I'm trying to do it in such a way that everything
that could be written to be inlined for specific sized vectors could
also be inlined in this generic sized vector.
For instance, I'm hoping that Vector<double, 2> and Vector<double, 15>
both have inlinable "operator+" calls.
I know this is premature optimization, but its more for practicing my
meta-programming skills