problem about default-arguments-Collection of common programming errors


  • pmr
    c++ design boolean default-arguments member-function
    We have several classes where a call to a member function may change state and sometimes not depending on a boolean with default value.A a;a.set( “foobar” );assert( a.changed() == true );versusA a;a.set( “foobar”, false );assert( a.changed() == false );Please note that those member functions are virtual. I would favor to use an alias to better read code and make a private member function still allowing the old method and give only the wrappers to the public:a.silentlySet( “foobar” ) {a.set( “foo

  • user974967
    c++ function-overloading default-arguments
    My program has a Car and CarManager class that looks similar to the following:#include <list>class Car { public:void Draw() { Draw(m_opacity); }void Draw(float opacity){}private:float m_opacity; };class CarManager { public://Draw cars using their m_opacity membervoid DrawCars() { for(auto i = m_cars.begin(); i != m_cars.end(); i++)i->Draw();}//Draw cars using opacity argumentvoid DrawCars(float opacity){for(auto i = m_cars.begin(); i != m_cars.end(); i++)i->Draw(opacity);}private:std

Web site is in building