So, you have types Inf1 and Inf2 that are related to each other, and at least one of them contains abstract methods.
You want to return some sub-implementation of Inf2 , but which one is determined at runtime.
This means that you need runtime polymorphism. There are three different ways you could approach this.
First, you can return a pointer - perhaps a smart pointer, such as unique_ptr , to a common interface. This requires free storage (heap), but it becomes clear, and this is the simplest answer.
Secondly, you can write an erasure object of type that provides a virtual version of non- virtual , and forwards some internal details. These internal details will ultimately use some kind of smart pointer or a third solution. The advantage here is that you can hide how you manage memory and just expose the semantics of value with a cheap move. The disadvantage is that there are many templates.
Thirdly, you can use something like boost::variant - a union for a set of types with means of protection against access to incorrect types. While boost cannot be used directly, the design can be simulated. The idea is that you have local storage in which you place new data, except, perhaps, for larger objects, where instead you use a smart pointer. Unlike the second solution, the set of supported types is explicitly specified in your type. This is the most difficult decision (if you do not have access to boost ) and requires that you have a fixed (at compile time) set of Inf2 implementations that all Inf1 users should have full information about.
As already noted, the first solution is the simplest. The costs of the first solution are based only on performance, and these performance results will not be difficult to fix after that fact, if you find them where there are real problems. Therefore, I would advise solution No. 1, and then a profile, to find out if the costs are too high. If the costs are high, go to Solution # 3, possibly into the shell of Solution # 2.