Thread: Derived class linking error

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282

    Derived class linking error

    I am working on a programming project from the book I am learning c++ from.

    I already have a base class and a derived class given to me (and they work properly, I checked). I am too make a derived class from the derived class.
    The derived class I am working on is called Administrator, the class I am deriving it from is called SalariedEmployee.

    I think my constructors are working correctly…Now, I have a simple main function that I am using trying to test my work so far.

    Code:
    #include <iostream>
    #include <string>
    #include "administrator.h"
    
    
    using namespace std;
    using namespace employeessavitch;
    
    int main()
    {
    
    	Administrator shane;
    	shane.set_supervisor();
    	//or shane.print() or shane.info_in()
    
    
    
    
    	return 0;
    }
    It compiles fine, but when I link I get the follow error:
    Code:
    5.obj : error LNK2001: unresolved external symbol "public: void __thiscall employeessavitch::Administrator::set_supervisor(void)"
     (?set_supervisor@Administrator@employeessavitch@@QAEXXZ)
    
    5.obj : error LNK2001: unresolved external symbol "public: __thiscall employeessavitch::Administrator::Administrator(void)"
     
    (??0Administrator@employeessavitch@@QAE@XZ)
    Debug/5.exe : fatal error LNK1120: 2 unresolved externals
    Error executing link.exe.
    And I get the same error for any function I have created (but replaced with the name of that function in the error). And I have made sure that the other classes the variables are under ‘protected’ and not ‘private’.

    Any ideas?
    *edit* I just noticed I am also getting a linking error when I try and call the constructor that takes values).....
    .h and .cpp from classes follow.

    Administrator.h
    Code:
    #ifndef ADMINISTRATOR_H
    #define ADMINISTRATOR_H
    
    #include <string>
    #include "salariedemployee.h"
    
    using namespace std;
    
    
    namespace employeessavitch
    {
    
    
    
    
    	class Administrator : public SalariedEmployee
    	{
    
    	public:
    
    
    		Administrator();
    		Administrator(string the_title, string the_position, double the_salary /*weekly*/, string the_supervisor,
     string the_name, string the_ssn );
    
    		void set_supervisor();
    		void info_in( ); 
    
    		void print();
    		void print_check();
    
    	
    
    
    	protected:
    		
    		
    		string Title;
    		string Position;
    		string Supervisor;
    
    	};
    
    
    }//empolyeessavitch
    
    
    #endif
    administrator.cpp
    Code:
    #include <string>
    #include <iostream>
    #include "administrator.h"
    using namespace std;
    
    
    
    namespace employeessavitch
    {
    
    
    	Administrator::Administrator() : SalariedEmployee(), Title("N/A"), Position("N/A"), Supervisor("N/A")
    	{
    		//Left blank
    	}
    
    
    	Administrator::Administrator(string the_title, string the_position, double the_salary, 
    string the_supervisor, string the_name, string the_ssn) :
    /* : */	SalariedEmployee(the_name, the_ssn, the_salary), Title(the_title), Position(the_position), Supervisor(the_supervisor)
    	{
    		//Left blank
    	}
    
    
    	void Administrator::set_supervisor() 
    	{
    		string temp;
    		cout << "Enter the new supervisor's name: ";
    		cin >> temp;
    
    		Supervisor = temp;
    	}
    
    
    	void Administrator::info_in()
    	{
    		
    		cout << "Enter the administrators title: ";
    		cin >> Title;
    		cout << "\nEnter the administrators position: ";
    		cin >> Position;
    		cout << "\nEnter the administrators weekly salary: ";
    		cin << salary;
    	}
    
    
    
    	void Administrator::print()
    	{
    
    		cout << "Output data to screen"; //finish later
    	}
    
    
    	void Administrator::print_check()
    	{
    
    		cout << "Output data in and info from base classes in check format"; //finish later
    	}
    
    
    }//employeessavitch
    Last edited by Enahs; 11-12-2005 at 09:38 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. Crazy errors caused by class, never seen before..
    By Shamino in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 11:54 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM