Which is the best method to use when we need to return different types in a C++ function. Can anybody suggest the best among template, boost variant, union?
In your situation i prefer boost::variant. You can go through the official documentation. http://www.boost.org/doc/libs/1_61_0/doc/html/variant.html Or you can see example illustrated in this blog. http://arunksmanjeri.blogspot.in/2016/10/return-different-types-using-boost.html?m=1