我使用c ++来学习类和流但是每次尝试我都会得到错误ostream没有命名类型我使用std命名空间,包含iostream,包含头
Uhr.cpp
#include<iostream>
#include"uhr.h"
using namespace std;
Uhr::Uhr(int Stunde, int Minute, int Sekunde){
this -> Stunde = Stunde;
this -> Minute = Minute;
this -> Sekunde = Sekunde;
}
void Uhr::setTime(int Stunde, int Minute, int Sekunde)
{
this -> Stunde = Stunde;
this -> Minute = Minute;
this -> Sekunde = Sekunde;
}
void Uhr::setOne()
{
this -> Sekunde=+Sekunde;
}
ostream& Uhr::print(ostream& o)
{
o = "Stunden " << Stunden << " Minuten " << Minuten <<" Sekunden" << Sekunden;
return o:
}
ostream& operator << (ostream &o,const Uhr& u)
{
return u.print(o);
}
uhr.h
#include<iostream>
class Uhr
{
private:
int Stunde;
int Minute;
int Sekunde;
public:
Uhr(int Stunde = 0, int Minute = 0, int Sekunde = 0);
void setTime(int Stunde, int Minute, int Sekunde);
void setOne();
ostream& print(ostream & o);
};
ostream& operator << (ostream &o,const Uhr& u);
错误: uhr.h:14:2:错误:'ostream'没有命名类型 ostream的和放; print(ostream&amp; o)const; ^ uhr.h:17:2:错误:'ostream'没有命名类型 ostream的和放;运算符&lt;&lt; (ostream&amp; o,const Uhr&amp; u);
答案 0 :(得分:1)
更改
insert
在您的标题文件ostream& print(ostream & o);
中
uhr.h