2014-11-21 2 views
0

C++로 프로그래밍 한 이후로 오랜 시간이 걸렸으며 구문에 익숙해지기 위해 몇 가지 연습 문제를 시도하고 있습니다. 저는 기본 클래스가 RetailEmployee이며 3 개의 파생 클래스가있는 프로그램을 작성하고 있습니다 : SalesEmployee, WarehouseEmployeeManagerEmployee. 나는 파생 클래스 중 하나 내 헤더의 상단에 다음과 같은 코드를 가지고 :C++ 파생 클래스 상속 메서드 오류

// Sales Employee Class Header 
#indef SalesEmployee 
#define SalesEmployee 

#include <stdio.h> 
#include "RetailEmployee.h" 

using namespace std; 

class SalesEmployee 
{ 
public: 
    SalesEmployee(string department, float pay, int ID, string name) 
. 
. 
. 

그러나, 언제 내가 방법이 없다는 오류를 얻을 SalesEmployee 인스턴스의 기본 클래스에서 메소드를 사용하려고 찾을 수 없습니다. 또한 모든 파일은 동일한 디렉토리에 있습니다.

누구에게 의견이 있습니까?

+3

클래스 SalesEmployee : public RetailEmployee {...} - 기본 클래스에서 상속해야합니다. 그것이 그대로, 그 자체의 수업. – Chris

+2

ifdef 가드는'#define SalesEmployee'가 아니어야합니다. #define SALES_EMPLOYEE_H와 같아야합니다. 그렇지 않으면 전처리기에 문제가 있는지 묻는 것입니다. – Barry

답변

2

class SalesEmployeeclass RetailEmployee의 자손임을 컴파일러에 지시하지 않았습니다. 그렇게하려면, 당신은해야합니다

class SalesEmployee : public RetailEmployee 
{ 

} 

는 또한 class RetailEmployee에 필요한 건설 초기화 정보를 함께 전달하는 class SalesEmployee에 대한 귀하의 생성자를 변경해야합니다. 이러한 당신의 SalesEmployee.cpp 구현 파일에서이 같은 : 그들은 모든 클래스에 공통해야하기 때문에

SalesEmployee::SalesEmployee(string department, float pay, int ID, string name) : RetailEmployee(department, pay, ID, name) 
{ 
    // Whatever special initialization SalesEmployee has goes here. 
} 

내가 회원이 실제로 기본 클래스에 정의 된 모든 데이터를 추정하고있다.