C++新手 error C2593: 'operator <<' is ambiguoe error C2593: 'operator >>' is ambiguous
#include<iostream>#include<iomanip>usingnamespacestd;classTime{private:inth;intm;ints...
#include<iostream>
#include<iomanip>
using namespace std;
class Time
{
private:
int h;
int m;
int s;
public:
friend ostream& operator<<(ostream&,Time&);
friend istream& operator>>(istream&,Time&);
Time()
{
h=0;
m=0;
s=0;
}
int geth() const{return h;}
int getm() const{return m;}
int gets() const{return s;}
};
ostream& operator <<(ostream &output,Time &a)
{
output<<setiosflags(ios::fixed)<<setprecision(4)<<a.h+a.m/60+a.h/3600;
return output;
}
istream& operator >>(istream& input,Time& b)
{
input>>b.h>>b.m>>b.s;
return input;
} 展开
#include<iomanip>
using namespace std;
class Time
{
private:
int h;
int m;
int s;
public:
friend ostream& operator<<(ostream&,Time&);
friend istream& operator>>(istream&,Time&);
Time()
{
h=0;
m=0;
s=0;
}
int geth() const{return h;}
int getm() const{return m;}
int gets() const{return s;}
};
ostream& operator <<(ostream &output,Time &a)
{
output<<setiosflags(ios::fixed)<<setprecision(4)<<a.h+a.m/60+a.h/3600;
return output;
}
istream& operator >>(istream& input,Time& b)
{
input>>b.h>>b.m>>b.s;
return input;
} 展开
3个回答
展开全部
class storehouse{
int mutex;
int count;
int max;
void save(){
int changed=false;
while(changed==false){
changed=true;
enter(mutex);
if(count<max)count++;
else changed=false;
leave(mutex);
sleep(0);
}
}
void sell(){
int changed=false;
while(changed==false){
changed=true;
enter(mutex);
if(count>0)count--;
else changed=false;
leave(mutex);
sleep(0);
}
}
}
class Producer{
produect(storehouse& store){
store.save();
}
}
class consumer{
consum(storehouse& store){
store.sell();
}
}
int main(){
storehouse store1;
vector<Producer> products;
vector<consumer> consums;
vector<std:thread> allthread;
while(products.size()||consums.size()){
if(products.size()) allthread.push_back(std::thread t(&Producer,products.pop_back()));
if(consums.size())allthread.push_back(std::thread(&consums.sell(),consums.pop_back()));
}
for(auto athread:allthread)athread.join();
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
编译时正常的啊,我是用vs编译的
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
dev-c++语法检查正常。0错误0警告。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询