K
kito
I'm not sure how to phrase this, so let me start by showing an
example:
template <class F>
struct Foo1
{
Foo1() {}
~Foo1() {}
F mInternalThing;
};
template <class F>
struct Foo2
{
Foo2() {}
~Foo2() {}
F mOtherThing;
};
template <class B>
struct Bar
{
Bar() {}
~Bar() {}
B mInternalFoo;
};
int main()
{
Bar<Foo1<int> > bar1;
Bar<Foo2<int> > bar2;
}
This code compiles and all is dandy. However, I want to be able to do
something like this:
int main()
{
Bar<Foo1> bar1;
}
and have the template parameters of Foo1 automagically be <int>. This
is because in my particular use case I know that the template
parameter of Bar has to be another template, and I know what the
template parameters of that template should be (int in this example).
I don't want main() to have to worry about that, because it's
essentially an internal detail of Bar. However, I still want Bar to be
a template class, because there are multiple different Foo types that
it can work with.
Is there any way to do this? I'm guessing not, since Foo1 isn't a type
until it has some template parameters. If not, then is there some
other way I should be structuring my code?
Sorry if this isn't clear. I can try to re-explain it if people can't
follow what I'm asking for.
example:
template <class F>
struct Foo1
{
Foo1() {}
~Foo1() {}
F mInternalThing;
};
template <class F>
struct Foo2
{
Foo2() {}
~Foo2() {}
F mOtherThing;
};
template <class B>
struct Bar
{
Bar() {}
~Bar() {}
B mInternalFoo;
};
int main()
{
Bar<Foo1<int> > bar1;
Bar<Foo2<int> > bar2;
}
This code compiles and all is dandy. However, I want to be able to do
something like this:
int main()
{
Bar<Foo1> bar1;
}
and have the template parameters of Foo1 automagically be <int>. This
is because in my particular use case I know that the template
parameter of Bar has to be another template, and I know what the
template parameters of that template should be (int in this example).
I don't want main() to have to worry about that, because it's
essentially an internal detail of Bar. However, I still want Bar to be
a template class, because there are multiple different Foo types that
it can work with.
Is there any way to do this? I'm guessing not, since Foo1 isn't a type
until it has some template parameters. If not, then is there some
other way I should be structuring my code?
Sorry if this isn't clear. I can try to re-explain it if people can't
follow what I'm asking for.