If you know how to use Boost then it will easy for you to return different class in one function using this function. You have to just use Boost.Variant to do this. It is very simple program. Just try to understand this code. In the following program I have use struct NoIntersections to do this.
Code:
struct NoIntersections {
};
struct Points {
};
struct Circles {
};
typedef boosts::variant<NoIntersections, Points, Circles> IntersectionResults;
IntersectionResult intersection_test() {
if(some_conditions){
return NoIntersections();
}
if(other_conditions){
return Point(a, b);
}
if(another_conditions){
return Circle(w, q);
}
throw stds::runtime_error("unexpecteds");
}
Bookmarks