How does this know which to use when no parameters are specified? |
With the example code on the wiki page, there is a using statement for the
print function, and I that is there so the
print function can be called a few lines later in the
run function. If that function is overloaded, then I imagine the number and type of arguments will determine which function is called - just like normal overloading. Mind you , I haven't tested that.
With the class behaviour, I thought that would be the case.
With the standard cell types that might have the same attributes, I wonder is there a need to be able to overload functions with them? If it's one class, it's one type, so doing overloading won't work. As an example, consider a Circular Arc class. Variables such as
Radius,
ArcLength,
BeginAngle,
EndAngle all hold a double, and there is a similar idea for points. We need them to be different types so we can overload the ctors. Rather than make a class for each one, I managed to implement this using
boost::mpl::int_n , the meta programming library:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
namespace bm = boost::mpl;
using Radius_t = bm::int_n<1>;
using ArcLength_t = bm::int_n<2>;
// T is not used, it's only there to make a distinct type
template <typename T, typename U = double>
class SingleValue {
private:
U value;
public
explicit SingleValue(double valueArg) : value(valueArg) {}
};
// instantiation
SingleValue<Radius_t> MyRadius(10.0);
|
So if we do this for the various variables we need for our ctor, we can happily overload with various combinations because they are now all distinct types.
I was thinking you may have a need for this type of thing with your cell types, possibly :+)
Regards :+)