2017-05-21 1 views
1

私は今これらの2つのファイルを取得し、いつでもコンパイルしたい文字列にBestellung.hの型エラーの名前を付けません。std :: string name;どうして ? THX main.cppにstd :: sting?文字列は型エラーの名前を付けません

#include "Bestellung.h" 
    #include <iostream> 
    using namespace std; 

    int main() 
    { 
     Bestellung(); 
     cout << Bestellung{"maki"} << endl;// [maki,10€] 
     return 0; 
    } 

Bestellung.cpp

#include "Bestellung.h" 

Bestellung(string bestellV,double preisV=10){ 
    name="bestell V"; 
    preis="preis V"; 
    }; 
string get_name const(Bestellung v) { 
    return Bestellung.name; 
    }; 
double get_preis const(Bestellung v){ 
    return Bestellung.preis; 
    }; 
ostream& print(ostream&) const{ 
    }; 

Bestellung.h

#ifndef BESTELLUNG_H 
#define BESTELLUNG_H 
#include <string> 
#include <iostream> 

class Bestellung{ 
private: 
    std::string name; 
    std::double preis; 

    public: 
    Bestellung(string,double=10); 
    string get_name const { 
    }; 
    double get_preis const{ 
    }; 
    ostream& print(ostream&) const{ 
    }; 

}; 
#endif 
+0

いくつかの場所で "bestellung.h"を使用すると、あなたは 'std ::'を必要としません。 –

答えて

0

あなたは、名前空間修飾子を使用する必要があります。あなたは持っている:

Bestellung(string,double=10); 

あなたが持っている必要があります。

Bestellung(std::string,double=10); 

あなたも持っている:

string get_name const { 

あなたが持っている必要があります。

std::string get_name const { 

をあなたはしたくない場合毎時std名前空間を指定するあなたは、文字列を使用する電子、あなたは先頭近くこれを行うことができます:

using std::string; 

ヘッダファイルにかかわらず、悪い習慣ですので、私が最初に言ったように私は完全な資格を使用することを行います。 このエラーを修正した後、同じことをostreamにも実行する必要があります。

名前空間の詳細については、hereを参照してください。

+0

何らかの理由で私がまだそこに達する前にエラーが発生します(Bestellung(std :: string、double = 10) std :: string nameの上に上記のエラーメッセージ行を出す;私はゆっくりと私のコンパイラが誤動作していると感じる – Latrellvie

関連する問題