c++constructorinitializationambiguitynamed-constructor

does adding a dummy parameter to constructors of a class to solve calling ambiguity, violate any rule?


take following class and two object definitions:

class Rect{
 public:
  enum centimeter;
  enum meter;
  Rect(double len,double wid,enum centimeter){
   length=(len/100);
   width=(wid/100);
  }
  Rect(int len,int wid,enum meter){
   length=len;
   width=wid;
  }
  //rest of implementation
 private:
  double length;//in meters
  double width;//in meters
};
Rect obj1(10,5,Rect::centimeter());
Rect obj2(10,5,Rect::meter());

two previous constructors have dummy enum parameters to solve calling ambiguity caused in case these dummy parameters didn't exist. Now in spite of possibility of using named constructors here, if I insist on using these dummy parameters, does this violate any coding rule that I should be aware of ?


Solution

  • STL uses that idiom to differentiate iterator types in lieu of concepts.