Sunday, September 22, 2013
Thursday, September 19, 2013
error messages & corrections
- error: declaration of ‘std::string GradeBook::getCourseName()’ outside of class is not definition [-fpermissive]:cause: semicolon in function definition in class implementation
- error : undefined refernce to class member.cause : constructor with no arguments was called as GradeBook my GradeBook();Eclipse gave an error for the same
- Time.h:24:11: error: ISO C++ forbids in-class initialization of non-const static member initialsing data members of a function: cause initialising data member of a class
Friday, September 13, 2013
questions
- can we have multiple constructors?
- how to ensure that multiple copies of same #include is not added to the code?
- do we need to declare a destructor both in the header & cpp file
- what is file scope?
- what is the difference b/w string & const string &?where do we use each?
daily learning
- When declared in header file the constructor has first bracket around it.
- the constructor initializes all data members of the object.the data members are provided as arguments to the constructor
- constructors when defined in a header doesnt require parameter names.only parameter type is needed
- if a constructor takes no arguments , then while calling it just use the name without any arguments.for eg GradeBook myGradeBook; & not GradeBook myGradeBook();.Eclipse gives an error for the same.
- each function in the implementation of a class is preceeded by class name followed by ::
- however if a function is called by a member of the same class then the classname & semicolon is omitted
- in the implementation of the class in the cpp file, we have to define the parameter type in each definition like void GradeBook::setCourseName(string new).This is despite the fact that we have declared the parameter type in the function interface.This is because of the fact that function overloading can happen, where the same function takes different parameters to function.
- Both the class interface & implementation end with semicolon(;).
- in the class implementation we must include scope, return type & parameter (with name)
- when the program is broken into main & other functions, it can be compiled using g++ main.cpp other.cpp.adding the header is not needed.i got error undefined reference to `GradeBook::GradeBook when i didnt add the other.cpp file.the other.cpp file had the class member function definition
- cin is an object of <istream>.istream member functions are get,getline, getblock etc.
- when using switch-case dont forget to add the default case.also dont forget the curly brackets for the switch statements
- we use const to a function to say that no data is modified in that function.This is done in function declaration in header as well as the function definition.
- destructor is created automatically by the compiler.however if it declared explicitely in the code then we need to define it in the member function declaration as well.it may have an empty body though.
Monday, September 9, 2013
meanings of c++ compliation errors
shorter list of common compile & link errors
http://www.csee.umbc.edu/courses/undergraduate/202/fall04/Projects/CommonErrors.shtml
common c++ errors:
http://wooden-robot.net/Docs/c++-compiler-errors.html
long list of common errors
http://web.mst.edu/~cpp/common/common_errors.html
list of compiler errors & meanings
http://docs.embarcadero.com/products/rad_studio/radstudio2007/RS2007_helpupdates/HUpdate4/EN/html/devwin32/cppcompmessagespart_xml.html
http://www.csee.umbc.edu/courses/undergraduate/202/fall04/Projects/CommonErrors.shtml
common c++ errors:
http://wooden-robot.net/Docs/c++-compiler-errors.html
long list of common errors
http://web.mst.edu/~cpp/common/common_errors.html
list of compiler errors & meanings
http://docs.embarcadero.com/products/rad_studio/radstudio2007/RS2007_helpupdates/HUpdate4/EN/html/devwin32/cppcompmessagespart_xml.html
Subscribe to:
Comments (Atom)