class linking problem

I am getting some errors in my program while trying to link two header files for my program and don't know why or what they mean..

Here are the errors:
- error LNK2019: unresolved external symbol "public: __thiscall EmployeeWithBankAccount::EmployeeWithBankAccount(class std::basic_string<char,struct std::char_traits<char>
- error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall Employee::get_name(void)const "

- fatal error LNK1120: 2 unresolved externals

Heres the code with the two header files at the top:
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef CCC_EMPL_H
#define CCC_EMPL_H

#include <string>

using namespace std;

/**
   A basic employee class that is used in many examples
   in the book "Computing Concepts with C++ Essentials"
*/
class Employee
{
public:
   /**
      Constructs an employee with empty name and no salary.
   */
   Employee();
   /**
      Constructs an employee with a given name and salary.
      @param employee_name the employee name
      @param initial_salary the initial salary
   */
   Employee(string employee_name, double initial_salary);
   /**
      Sets the salary of this employee.
      @param new_salary the new salary value
   */
   void set_salary(double new_salary);
   /**
      Gets the salary of this employee.
      @return the current salary
   */
   double get_salary() const;
   /**
      Gets the name of this employee.
      @return the employee name
   */
   string get_name() const;
private:
   string name;
   double salary;
};

#endif 

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
#ifndef EMPLOYEEWITHBANKACCOUNT_H
#define EMPLOYEEWITHBANKACCOUNT_H

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

using namespace std;

class BankAccount
{
public:
   BankAccount() : balance(0) {};
   void deposit(double amount){ balance += amount; }
   void withdraw(double amount){ balance -= amount; }
   double get_balance(){ return balance; }
private:
   double balance;
};

class EmployeeWithBankAccount : public Employee
{
public:
   EmployeeWithBankAccount(string name, double salary, BankAccount *ba);
   void transfer_to_account(double amount);
   void print() const;
   BankAccount *account;
};

#endif 

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <vector>

/*
	Craig Ashworth
	4/20/11
*/

using namespace std;

#include "EmployeeWithBankAccount.h"

vector<EmployeeWithBankAccount> employees;

void readin()
{
  string name;
  string lname = "";
  double salary;
  BankAccount *ba = NULL;
  while (cin >> name >> salary)
  {
    int pos = name.find_first_of(',');
    string ln = name.substr(0,pos);
    if (ln != lname) 
    {
      ba = new BankAccount;
    }
    EmployeeWithBankAccount emp(name, salary, ba);
    employees.push_back(emp);
    lname = ln;
  }
}

void deposit(double amount)
{ 
	double balance = 0.0;
	balance += amount; 
}

void printall()
{
	for(int i = 0; i < 10; i++)
	{
		cout << employees[i].get_name() << " " 
			 << employees[i].account->get_balance() << "\n";
	}
}

int main()
{
   double amount = 0.0;
   readin();
   deposit(amount);
   printall();
}


I don't know if this is why, but you're inheriting EmployeeWithBankAccount and acting as if it has Employee's private members.

You don't inherit private members, if you want to inherit private members you must make them protected members so they remain encapsulated but still get inherited.
So how is the best way to do that?
Change 'private:' to 'protected:' in the class definition, then it will still be private, but it will also be inherited too.
Still getting the same errors
Topic archived. No new replies allowed.