Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Use this...
- class foo
- {
- private:
- std::string name_;
- unsigned int age_;
- public:
- foo(const std::string& name = "", const unsigned int age = 0) :
- name_(name),
- age_(age)
- {
- ...
- }
- };
- // Or this?
- class foo
- {
- private:
- std::string name_;
- unsigned int age_;
- public:
- foo() :
- name_(""),
- age_(0)
- {
- }
- foo(const std::string& name, const unsigned int age) :
- name_(name),
- age_(age)
- {
- ...
- }
- };
- foo f1;
- foo f2("Name", 30);
- class Vehicle {
- public:
- Vehicle(int wheels, std::string name = "Mini");
- };
- Vehicle x = 5; // this compiles just fine... did you really want it to?
- class Thingy2
- {
- public:
- enum Color{red,gree,blue};
- Thingy2();
- Thingy2 & color(Color);
- Color color()const;
- Thingy2 & length(double);
- double length()const;
- Thingy2 & width(double);
- double width()const;
- Thingy2 & height(double);
- double height()const;
- Thingy2 & rotationX(double);
- double rotationX()const;
- Thingy2 & rotatationY(double);
- double rotatationY()const;
- Thingy2 & rotationZ(double);
- double rotationZ()const;
- }
- main()
- {
- // gets default rotations
- Thingy2 * foo=new Thingy2().color(ret)
- .length(1).width(4).height(9)
- // gets default color and sizes
- Thingy2 * bar=new Thingy2()
- .rotationX(0.0).rotationY(PI),rotationZ(0.5*PI);
- // everything specified.
- Thingy2 * thing=new Thingy2().color(ret)
- .length(1).width(4).height(9)
- .rotationX(0.0).rotationY(PI),rotationZ(0.5*PI);
- }
- // Header
- void doSomething(int i = 25) ;
- // Source
- void doSomething(int i)
- {
- // Do something with i
- }
- // Header
- void doSomething() ;
- void doSomething(int i) ;
- // Source
- void doSomething()
- {
- doSomething(25) ;
- }
- void doSomething(int i)
- {
- // Do something with i
- }
- foo bar[400];
- foo bar("david", 34)[400]; // NOPE
Add Comment
Please, Sign In to add comment