2017-05-21 27 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

相关问题