hope you guys can help with this: I have the following function that should return an object Foo, in this case with a specific types:
Foo<int,bool> make_my_foo_object() {
return make_foo(10);
}
in my Foo class I have:
template <class A, class B>
struct Foo {
Foo(A aa): a(aa) {}
Foo(B bb): b(bb) {}
A a;
B b;
};
Then, in my make_foo function I have:
template<typename A, class B>
Foo<A,B> make_foo(A a) {
return Foo<A,B>(a); // this should call the Foo(A) ctor
};
I know this is not possible as there is no way in this simple implementation that B can be infer from the return type of make_foo.
The make_my_foo_object make not much sense in this context, but the whole idea is dealing with template params that cannot be deduced as they are missed.
What I'm trying to avoid is to specify the types in the return make_foo<int, bool>(10); in the make_my_foo_object function.
Do you guys think there is a possible workaround to this? or it's a no-go!
Any help or information will be appreciated. Thanks.
Aucun commentaire:
Enregistrer un commentaire