hello,

i have been stuggling with c++, i need to compile the following files but it never works always tell me the redefinition error i have tried both g++ and visual c++ but i can't make it work, i wish anybody can tell me why here are my codes please help, i have uploaded all my files please tell me what to do.

thanks

Attachments
#include <iostream>
#include "Employee.h"

Employee::Employee(char* name,int age, float salary)
				: Person (name, age),
				  salary_ (salary)
{
cout << "Employee constructor called" << endl;
}

void Employee::EmployeeDisplay() const
{
			Display();	// Call Person Display
			cout << "Salary = $" 			// Display salary_
								<< salary_ 
								<< endl;	
}
 
Employee::Employee(Employee const & e) 
   
			: Person(e), 
			  salary_(e.salary_)

{
		cout << "Employee copy constructor called" << endl;
}
Employee& Employee::operator=(Employee const & rhs)  
{
		cout << "Employee assignment operator called" << endl;

	if (this == &rhs)			
		return *this;
		
	Person::operator=(rhs);	// Call Person 
																									// assignment operator
	salary_ = rhs.salary_;
	
	return *this;
}
#include "Person.h"

class Employee: public Person
{
		public:
				Employee(char * name = 0, int age	= 0, float	salary = 0);
		 
				Employee(Employee const & e); 
		  
				Employee& operator=(Employee const & rhs);
		
				virtual ~Employee();
		
				void EmployeeDisplay() const;
		private:
				float salary_;
};
#include <iostream>
#include "Person.h"

using namespace std;

Person::Person(char* name,int age)	
			 			: name_(name),age_(age)
{	
		cout << "Person constructor called" << endl;
}
Person::Person(Person const & p) 
 
		  : name_(p.name_),
		   	age_(p.age_)

{
		cout << "Person copy constructor called" << endl;	
}
void Person::Display() const
{
		cout << "Name = " << name_ << endl;
		cout << "Age = " << age_ << endl;
}
Person& Person::operator=(Person const & rhs)   
{
		cout << "Person assignment operator called" << endl;

		if (this == &rhs)			
				return *this;
		
		name_ = rhs.name_;
		age_ = rhs.age_;
	
		return *this;
}
#include <string>

class Person
{
		public:
				Person(char * name = 0,int	age   = 0);
			 	Person(Person const & p);   
				Person& operator=(Person const & rhs);
				virtual ~Person(); 
				void Display() const;		
		private:
				char* name_ ;
				int	age_;
};

Nobody is going to download 5 files just to help you. My suggestion is that you remove everything you can without removing the error itself (but if you do, note what you took out). Then you'll be in a better position to debug. Who knows? The code may be short enough to post here at that point.

Well, I haven't seen the files but here is my guess. The most common reason while compilation of this error is that, you include a file in one file and include the same file in some file (there is no problem so far) and after that in some other file, you include both files, now since both files contains the definations of the original file, the compiler goes through the first one and when it finds that the other file also has the same definations that the other had, then it start complaining.

I suggest to use inclusion guards (preferably in all the files, with different identifiers) and try your code, like

#ifndef _MY_HEADER_FILE_
#define _MY_HEADER_FILE_

// ... Here goes the implementations

#endif // _MY_HEADER_FILE_

If the problem persists, please post the error code with its descripition.

>_MY_HEADER_FILE_
This invades the implementation's name space. Names with a leading underscore have a tendency to be reserved by the language definition for an implementation's use.

ok,

ifndef MY_HEADER_FILE
#define MY_HEADER_FILE

// ... Here goes the implementations

#endif // MY_HEADER_FILE

This article has been dead for over six months. Start a new discussion instead.