我现在有这两个文件,任何时候我想编译我都会收到错误
在
string
未命名类型
Bestellung.h
的{{1}}行中的为什么呢?
std::string name;
#include "Bestellung.h"
#include <iostream>
using namespace std;
int main()
{
Bestellung();
cout << Bestellung{"maki"} << endl;// [maki,10€]
}
#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 {
};
答案 0 :(得分: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。