Derived class in main

I can't figure out why when I try to declare a function of a derived class in the main part of my program, I get an error saying 'SalariedEmployee' undeclared (first use this function).

This is my main:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <cstdlib>
#include "salariedemployee.h"

using namespace std;

int main()
{
    SalariedEmployee define;
    
    
    system("pause");
    return 0;
}


I'm trying to use SalariedEmployee which is a derived class of Employee, but I'm getting an error saying SalriedEmployee is undeclared.

This is the SalariedEmployee derived class:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef SALARIEDEMPLOYEE_H
#define SALARIEDEMPLOYEE_H

#include <string>
#include "employee.h"

using namespace std;

namespace employeessavitch
{

    class SalariedEmployee : protected Employee
    {
    public:
        SalariedEmployee( );
        SalariedEmployee (string the_name, string the_ssn,
                                  double the_weekly_salary);
        double get_salary( ) const;
        void set_salary(double new_salary); 
        void print_check( );						
    private:
        double salary;//weekly
    };

}//employeessavitch

#endif //SALARIEDEMPLOYEE_H 


This is the Employee base class:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#ifndef EMPLOYEE_H
#define EMPLOYEE_H

#include <string>
using namespace std;

namespace employeessavitch
{

    class Employee
    {
    public:
        Employee( );
        Employee(string the_name, string the_ssn);
        string get_name( ) const;
        string get_ssn( ) const;
        double get_net_pay( ) const;
        void set_name(string new_name); 
        void set_ssn(string new_ssn);
        void set_net_pay(double new_net_pay);
        void print_check( ) const;
    protected:
        string name; 
        string ssn; 
        double net_pay;
    };

}//employeessavitch

#endif //EMPLOYEE_H 



I feel like there must be something I'm missing, but I'm not sure what it could be.
SalariedEmployee is inside the employeessavitch namespace. It should work if you change line 9 in main to employeessavitch::SalariedEmployee define;.
Okay, that seems to have helped in allowing me to compile more. Though I'm still getting an error: "[Linker error] undefined reference to `employeessavitch::SalariedEmployee::SalariedEmployee()' "

I'm trying to now use some of the functions in the Employee.h by typing something like define.set_name("John Doe"); for set_name.

Is that the correct way to implement these functions? Cause when I try to do so I get an error saying
"void employeessavitch::Employee::set_name(std::string)' is inaccessible"
within context
"employeessavitch::Employee' is not an accessible base of `employeessavitch::SalariedEmployee' "
u using explicit instantiation method .

try include the other header
Do you mean replace

employeessavitch::SalariedEmployee define;

with

employeessavitch::Employee define;
The problem is that the linker can't find the definitions of the member functions. If you have more source files make sure that you compile and link them all.
I have an include directive for employee.h and salariedemployee.h in int main(). My derived class salariedemployee.h has an include directive for the base class employee.h as well. Both of my .cpp files also have their header files #included.

I am still getting a linker error when trying to compile in main. I have a total of 5 source files. Are there any include directives that I could be missing still?
The includes are not the problem. If you are using an IDE make sure that all .cpp files have been added to the project.
and dont exclude any file
make all file included . what compiler you using.
those cpp file also dont exclude it
Topic archived. No new replies allowed.