Wednesday, May 22, 2013

Common Errors in C++

  1. string: #include <string> when using std::string
  2. header: #include "BaseClass.h" when doing inheritance 
  3. main, header: #include "RelevantClass.h" in main function 
  4. basic IO: #include <iostream> when using cout cin endl 
  5. method: in cpp, ReturnType ClassName::method(int& para){};
  6. Precedence <<: shall cout<<(string1==string2); rather than cout<<string1==string2;
  7. new: Class* ptr = new Class; rather than Class* ptr = new Class(); unless you got a constructor with Class(para=default)]
  8. static: static methods correspond to static attributes
  9. Overloading "<<"
    1. inside class: ostream& operator<<(ostream& ostr)
    2. outside class: ostream& operator<<(ostream& ostr, Class& obj)
    3. the method itself: return ostr<<string1+string2+string3;


No comments:

Post a Comment