Thread: Need someone help!!!

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    5

    Red face Need someone help!!!

    I have the files of my program as following:
    main.cpp
    employee.cpp
    fullTime.cpp
    partTime.cpp
    employee.h
    fulltime.h
    partTime.h
    I've got so much link errors of this program.
    What's the problem of them?
    Thanks for anyone's help!!

    +++++++++++++++++++++++++++++++++++++++++++++
    main.cpp
    ---------
    #include <iostream.h>
    #include <string.h>
    #include "Employee.h"
    #include "fullTime.h"
    #include "partTime.h"

    void main()
    {
    Employee* emploPtr[2];
    Employee e("Johnny", 40000);
    fullTime *ft = new fullTime("John", 30000, 10);
    fullTime ft1("Dr. John", 50000, 20);
    partTime pt("Patrick", 5000, 300, 100);
    emploPtr[0]=&e;
    emploPtr[1]=&pt;
    for ( int i = 0; i < 2; i++)
    if (emploPtr[i] -> calculateSalary() <= 40000)
    emploPtr[i]->printAll();
    cout << endl;
    ft->calculateSalary();
    ft->printAll();
    cout << endl;
    ft1.calculateSalary();
    ft1.printAll();
    }
    +++++++++++++++++++++++++++++++++++++++++++++
    employee.cpp
    ---------
    #include<iostream.h>
    #include<string.h>
    #include"Employee.h"

    Employee::Employee(char* N="", float sal=0)
    {
    strcpy(Name,N);
    salary=sal;
    }

    char* Employee::getName()
    {
    return Name;
    }

    float Employee::calculateSalary()
    {
    return salary;
    }

    void Employee:rintAll()
    {
    cout<<"Name :"<<Name<<endl;
    cout<<"Salary :"<<salary<<endl;
    }
    +++++++++++++++++++++++++++++++++++++++++++++
    fullTime.cpp
    ---------
    include<iostream.h>
    #include<string.h>
    #include"Employee.cpp"
    #include"fullTime.h"

    fullTime::fullTime(char *N, float sal, int y):Employee(N, sal)
    {
    year=y;
    }

    float fullTime::calculateSalary()
    {
    if(year>15)
    salary =salary *2/10 +salary;
    else
    salary =salary *1/10 +salary;

    return salary;
    }

    void fullTime:rintAll()
    {
    Employee:rintAll();
    cout<<"Employee worked year : "<<year<<endl;
    }
    +++++++++++++++++++++++++++++++++++++++++++++
    partTime.cpp
    ---------
    #include<iostream.h>
    #include<string.h>
    #include"Employee.cpp"
    #include"partTime.h"

    partTime:artTime(char *N, float sal, float pay, int h):Employee(N, sal)
    {
    hourlyPay=pay;
    hours=h;
    }

    float partTime::calculateSalary()
    {
    salary=salary+hours*hourlyPay;
    return salary;
    }

    void partTime:rintAll()
    {
    Employee:rintAll();
    cout<<"Working hours : "<<hours<<endl;
    cout<<"Hourly pay :"<<hourlyPay<<endl;
    }
    +++++++++++++++++++++++++++++++++++++++++++++
    employee.h
    ---------
    #ifndef EMPLOYEE_H
    #define EMPLOYEE_H

    class Employee
    {
    public:
    Employee(char* N, float);
    char* getName();
    float calculateSalary();
    void printAll();
    protected:
    char* Name;
    float salary;
    };
    #endif
    +++++++++++++++++++++++++++++++++++++++++++++
    fulltime.h
    ---------
    #ifndef FULLTIME_H
    #define FULLTIME_H
    #include "Employee.h"

    class fullTime: private Employee
    {
    public:
    float calculateSalary();
    void printAll();
    fullTime(char*, float, int);
    private:
    int year;
    };

    #endif
    +++++++++++++++++++++++++++++++++++++++++++++
    partTime.h
    ---------
    #ifndef PARTTIME_H
    #define PARTTIME_H


    class partTime: public Employee
    {
    public:
    float calculateSalary();
    void printAll();
    partTime(char*, float, float, int);
    private:
    float hourlyPay;
    int hours;
    };
    #endif

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    81
    Did you check the header file names of the preprocessor as it is case-sensitive?

    gogo

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    I gave you a pointer safe class for your employ class yet you rip the guts of the memory management from it.Are you some sort of idiot. You have a char* that points at nothing and you are storing data there. In the constructor you must allocate memory to your pointer so you have some where to actually store data.Also remember that as you are dealing with a pointer to a dynamically allocated chunk of memory you must write a copy constructor and an assignment operator because the default compiler produced functions only do a bitwise copy which would mean you would end up with two objects that pointed at the same piece of data rather than a copy. This is an explosion waiting to happen.
    Go back to your other post and look at the code i gave you.I only wrote the most important functions for you so that you could see how the memory was managed in your class. If there is something you dont understand then dont hesitate to ask.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    5
    Thanks a lot
    I will go check the problems of my program again

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    5
    Link errors
    I got the link errors as the following:

    Linking...
    fullTime.obj : error LNK2005: "public: __thiscall Employee::Employee(void)" (??0Employee@@QAE@XZ) already defined in Employee.obj
    fullTime.obj : error LNK2005: "public: __thiscall Employee::Employee(char *,float)" (??0Employee@@QAE@PADM@Z) already defined in Employee.obj
    fullTime.obj : error LNK2005: "public: char * __thiscall Employee::getName(void)" (?getName@Employee@@QAEPADXZ) already defined in Employee.obj
    fullTime.obj : error LNK2005: "public: float __thiscall Employee::calculateSalary(void)" (?calculateSalary@Employee@@QAEMXZ) already defined in Employee.obj
    fullTime.obj : error LNK2005: "public: void __thiscall Employee:rintAll(void)" (?printAll@Employee@@QAEXXZ) already defined in Employee.obj
    partTime.obj : error LNK2005: "public: __thiscall Employee::Employee(void)" (??0Employee@@QAE@XZ) already defined in Employee.obj
    partTime.obj : error LNK2005: "public: __thiscall Employee::Employee(char *,float)" (??0Employee@@QAE@PADM@Z) already defined in Employee.obj
    partTime.obj : error LNK2005: "public: char * __thiscall Employee::getName(void)" (?getName@Employee@@QAEPADXZ) already defined in Employee.obj
    partTime.obj : error LNK2005: "public: float __thiscall Employee::calculateSalary(void)" (?calculateSalary@Employee@@QAEMXZ) already defined in Employee.obj
    partTime.obj : error LNK2005: "public: void __thiscall Employee:rintAll(void)" (?printAll@Employee@@QAEXXZ) already defined in Employee.obj
    Debug/project.exe : fatal error LNK1169: one or more multiply defined symbols found
    ------------------------------------------------------------
    How can I solve these link errors?
    Thanks a lot

  6. #6
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    Posts
    133
    Run time error:
    fullTime.obj : error LNK2005: "time: __thiscall me::me(tired)" (??me@@QUITE@ZZZZZ) already defined in sleep.obj
    C++ Is Powerful
    I use C++
    There fore I am Powerful

  7. #7
    Registered User zahid's Avatar
    Join Date
    Aug 2001
    Posts
    531
    Hi Joy,
    Is your program running properly now?
    [ Never code before desk work ]
    -------------------------------------:-->
    A man who fears Nothing is the man who Loves Nothing
    If you Love Nothing, what joy is there in your life.
    =------------------------------------------------------= - I may be wrong.

  8. #8
    Unregistered
    Guest
    in parttime.cpp and fulltime.cpp it should be

    #include "Employee.h"

    not

    #include "Employee.cpp"

    Then I think you might want to review how class inheritance, virtual functions, and overloading functions relate to one another.

  9. #9
    Unregistered
    Guest
    drop #include "Employee.cpp" from fulltime.cpp. The Employee.cpp file will be linked by the line #include "Employee.h" in fulltime.h. Drop #include "Employee.cpp" from parttime.cpp for same reason. Add #include "Employee.h" to parttime.h.

Popular pages Recent additions subscribe to a feed