2017-05-21 2 views
1

지금이 두 파일을 얻었고 언제든지 컴파일하려고합니다. 문자열이 Bestellung.h에서 형식 오류의 이름을 지정하지 않습니다 std :: string name; 왜 ? 들으 MAIN.CPPstd :: 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

관련 문제