Answer to Question #29933 in C++ for rishi taukoordass
Question #29933
Implement a thread safe class to manage a queue of objects.Accessing the front of the queue should be a blocking operation when the queue is empty.
Expert's answer
#include<iostream>
#include<string>
#include<queue>
using namespace std;
class safe:public queue<double>{
public:
double front(){
if (this->empty()==1) return 0;
else return this->queue::front();
}
};
int main()
{
safe s;
s.push(1);
cout<<s.front()<<endl;
s.pop();
cout<<s.front()<<endl;
system("PAUSE");
return 0;
}
#include<string>
#include<queue>
using namespace std;
class safe:public queue<double>{
public:
double front(){
if (this->empty()==1) return 0;
else return this->queue::front();
}
};
int main()
{
safe s;
s.push(1);
cout<<s.front()<<endl;
s.pop();
cout<<s.front()<<endl;
system("PAUSE");
return 0;
}
Need a fast expert's response?
Submit orderand get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Comments
Leave a comment