2016-11-16 3 views
-1

こんにちは私は、時間と日付へのアクセスを得るために、私のソースファイルAppointment内のクラスにアクセスしようとしています。私の問題は、私がこれをすると、私がタブを切り替えるとすぐに、継承が脱落し、もはや予定を見つけることができなくなるということです。継承のためのソースファイル内のクラスへのアクセス

これは私のソースファイルです。

これは、アポイントを継承しようとしているクラスです。

#include <iostream> 
    using std::ostream; 
    using std::istream; 
    #ifndef Session_H 
    #define Session_H 
    class Session : public Appointment 
{ 
    protected: 
    string client_id, fname, lname; 
    int charge; 
    public: 
Session(); 
string get(); 
string get_id() const; 
string get_fname() const; 
string get_lname() const; 
int calc_charge(); 
~Session(); 
}; 
#endif 
+0

「私の問題は、すぐに私はタブに継承delinksを切り替えて、私はこれを行うときということですアポイントメントを見つけることができなくなりました。それはどういう意味ですか? – HazemGomaa

+0

あなたは時刻と日付のアクセス権を公開しているので、アクセスするために継承する必要はありません! – HazemGomaa

答えて

0

あなたは、ソースファイル含める必要があります。それは内部に含ま警備員が何かする前に、ファイルの最上部に属していることがわかり、また

#ifndef Session_H 
#define Session_H 
#include <iostream> 
#include "Appointment.h" // or whatever the source file is named 

// These really shouldn't be here (namespace pollution)  
using std::ostream; 
using std::istream; 
using std::string; 

class Session : public Appointment 
{ 
protected: 
string client_id, fname, lname; 
int charge; 
public: 
Session(); 
string get(); 
string get_id() const; 
string get_fname() const; 
string get_lname() const; 
int calc_charge(); 
~Session(); 
}; 
#endif 

を(それは絶対にすべてを確保するために繰り返される封入から保護される)。言い換えれば、ヘッダーとして使用されるすべてのファイルにはガードが含まれている必要があります。期間。ここで

EDIT

は、物事をより適切にレイアウトされるかもしれない方法の例です:

// Appointment.h 

#ifndef Appointment_H 
#define Appointment_H 
#include "Chronos.h" // Or wherever your Date and Time objects are defined 

class Appointment 
{ 
    protected: 
    Date date; 
    Time start_time, end_time; 
    char description[40], location[40]; 
    public: 
    Appointment(); 
    void get(); 
    void print() const; 
    Date get_date() const; 
    Time get_start_time() const; 
    Time get_end_time() const; 
}; 
#endif 


// Session.h  


#ifndef Session_H 
#define Session_H 
#include <iostream> 
#include <string> 
#include "Appointment.h" 

// These really shouldn't be here (namespace pollution)... 
using std::string;  
using std::ostream; 
using std::istream; 

class Session : public Appointment 
{ 
protected: 
    string client_id, fname, lname; 
    int charge; 
public: 
    Session(); 
    string get(); 
    string get_id() const; 
    string get_fname() const; 
    string get_lname() const; 
    int calc_charge(); 
    ~Session(); 
}; 
#endif 

// main.cpp  

#include "Session.h" 

int main() 
{ 
    Session session; 
}  
+0

ありがとうございます。しかし、予定クラスはmainと同じファイルにあり、したがって.cppファイルです。 –

+0

さて、あなたのコード構成はすべて間違っています。あなたはヘッダーから.cppファイルを含めるべきではありません。これは次のようなものでなければなりません: –

+0

オリジナルの投稿の更新されたコードを見てください。 –

関連する問題