default constructor

I am trying to uderstand how default constructors work. Can someone please show me how they would be included in the following example not a perfect code I know, just trying to determine where it would fit in. Thanks

private:
.....int homework;
.....int quizzes;
.....int finals;

public:
....void setGrades(int ahomework, int aquizzes, int afinals) {...........}

.....int gethomework( ) {......}
.....int getquizzes( ) {.......}
.....int getfinals( ) {......}
.....int calculatescores( ){.......}
.....void printGrades( ) {.......}

};
Last edited on
 
std::string myName;  // Runs the default constructor (ie, the constructor that takes no parameters) 


In this case, the default constructor sets the string to an empty string (what else would it do?)

Example default constructor:

1
2
3
4
5
6
7
8
class Foo {
    int bar;
    int baz;
  public:
    Foo()  // default constructor - takes no parameters
        : bar(), baz()   // this is better than bar = 0; baz = 0;
    {} // body of constructor is empty
};

Topic archived. No new replies allowed.