I have a person class:

class person {
  protected:
    string fname, lname, gender bdate;

  public:
    person();
    // getters and setters

};

and a student class:

class student: public person {
  private:
    string major, grade;

  public:
    student();
    // getters and setters

}

}

I'm not sure how to make the implementation file. Should it be something like:

student::student() : person(), major( new_major ), grade( new_grade ) {}

I've read a book and checked online but I never get to see a fully used derived class to see what everything looks like, including the declaration. Any assistance would be greatly appreciated.

Are you offended? You missed my point.
Actually one of links i gave have even example that is very similar to your problem. I did it as part to help, and you get me back such discouraging answer, very sad!

Anyway here is the example from:
http://www.codersource.net/cpp_tutorial_inheritance.html

class vehicle //Sample base class for c++ inheritance tutorial
    {
     protected:
        char colorname[20];
        int number_of_wheels;
     public:
        vehicle();
        ~vehicle();
        void start();
        void stop();
        void run();
      };

     class Car: public vehicle //Sample derived class for C++ inheritance tutorial
     {
       protected:
          char type_of_fuel;
       public:
          Car();
     };

That won't work.

class person {
  protected:
    string fname, lname, gender bdate;

  public:
    person();
    // getters and setters

};
class student: public person {
  private:
    std::string major, grade; //note the std:: qualifier

  public:
    student(std::string new_major, std::string new_grade);
    // getters and setters (aka accessors and mutators)

}
//------------ implementation file: ///////////////
student::student(std::string new_major, std::string new_grade) : major( new_major ), grade( new_grade ) {}
//you don't need : person() here because you have already declared that student is derived from person here:
//class student: public person {

The main problem is that you were using a default constructor (no arguments) and trying to pass it two arguments!

Also, this is not really "making the implementation file", it is just defining one constructor.

Hope that helps.

Dave

1) Implement the person definition. Make sure You have all needed
constructor, for it will be used in the derived class.

2) Implement student class but in the constructor you need to pass
it the information needed to person class.

class person
{
   private : string name;
   public : person(string str) : name(str) { }
};
class Programmer : public person
{
   private :  string Language;
   public : Programmer(string name, string language ) : person(name), Language(language) { }
};

If you do not explicitly provide the programmer class with a person
constructor, the compiler will use the default constructor. If there
is no matching constructor, it will throw an error.

Thanks for the help.

I did it as part to help, and you get me back such discouraging answer, very sad!

I'm the kind of person that googles everything first. I'm pretty sure everyone does. That's the point of my response.

Thanks for the help.

I'm the kind of person that googles everything first. I'm pretty sure everyone does. That's the point of my response.

Don't worry, hope other have done what I failed to do :)
no hate, more of love :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.