Add ostream operator overload for Bureaucrat and clean up main function
This commit is contained in:
parent
5410b6228c
commit
37300e08a6
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#define HIGHEST_GRADE 1
|
#define HIGHEST_GRADE 1
|
||||||
#define LOWEST_GRADE 150
|
#define LOWEST_GRADE 150
|
||||||
@ -38,3 +39,5 @@ public:
|
|||||||
const char *what() const throw();
|
const char *what() const throw();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &os, const Bureaucrat &bureaucrat);
|
||||||
@ -88,3 +88,9 @@ const char * Bureaucrat::GradeTooLowException::what() const throw()
|
|||||||
{
|
{
|
||||||
return "Grade too low!";
|
return "Grade too low!";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &os, const Bureaucrat &bureaucrat)
|
||||||
|
{
|
||||||
|
std::cout << bureaucrat.getName() << ", bureaucrat grade " << bureaucrat.getGrade();
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|||||||
@ -15,6 +15,7 @@ int main (void)
|
|||||||
{
|
{
|
||||||
std::cerr << "Caught exception: " << e.what() << std::endl;
|
std::cerr << "Caught exception: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Bureaucrat alice("alice", 151); // This should also throw an exception
|
Bureaucrat alice("alice", 151); // This should also throw an exception
|
||||||
@ -23,6 +24,7 @@ int main (void)
|
|||||||
{
|
{
|
||||||
std::cerr << "Caught exception: " << e.what() << std::endl;
|
std::cerr << "Caught exception: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Bureaucrat charlie("charlie", 1);
|
Bureaucrat charlie("charlie", 1);
|
||||||
@ -32,6 +34,7 @@ int main (void)
|
|||||||
{
|
{
|
||||||
std::cerr << "Caught exception: " << e.what() << std::endl;
|
std::cerr << "Caught exception: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
|
std::cout << jan << std::endl;
|
||||||
|
std::cout << copy << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user