2017-04-12 11 views
-1

私は冒頭にこのコードを持っています:struct便が主要部分とタイプを指していない時にはメンバーflight_timeを持っていないことをコンパイラは、私の構造体のメンバーを認識しない

#include<iostream> 

using namespace std; 

struct mehmandar{ 

    char name[30]; 
    char last_name[30]; 
    long national_code; 
    long personal_code; 
    date birthday; 
    date employ_date; 
    mehmandar * nxt; 
}; 

struct time{ 

    int hour; 
    int min; 
}; 


struct flight{ 

    long flight_serial; 
    long plane_serial; 
    char from[30]; 
    char to[30]; 
    int traveller_num; 
    char pilot_name[30]; 
    char pilot_lastnam[30]; 
    mehmandar* mehmandar_majmue=NULL; 
    long total_price; 
    time flight_time; 
    flight * nxt; 
}; 

int main() { 

    flight* temp=new flight; 

    cin >>temp->flight_time.hour; 

    return 0; 
} 

が、その後、私はエラーを取得します構造体の飛行部分にあります。

+2

「フライト・テンポラリ」と言うと、オブジェクトをヒープ・アロケートするのはなぜですか? – cdhowie

+4

'namespace std;'を使うとどうなりますか? – NathanOliver

+2

あなたのタイプ 'time'の名前を' time_type'のように変更しようとしてください。 – KonstantinL

答えて

3

グローバルタイプとしてtimeを使用しないでください。同じ名前の標準ライブラリ関数と競合します。

my_timeに変更するか、自分の名前空間に入れます。例:

#include<iostream> 

namespace MyApp 
{ 
    struct time 
    { 
     int hour; 
     int min; 
    }; 

    struct flight 
    { 
     long flight_serial; 
     long plane_serial; 
     char from[30]; 
     char to[30]; 
     int traveller_num; 
     char pilot_name[30]; 
     char pilot_lastnam[30]; 
     long total_price; 
     time flight_time; 
     flight * nxt; 
    }; 
} 

int main() 
{ 
    using namespace MyApp; 
    flight* temp=new flight; 

    std::cin >>temp->flight_time.hour; 

    return 0; 
} 
関連する問題