Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- friend bool operator<<(obj const& lhs, obj const& rhs);
- ostream& operator<<(obj const& rhs);
- friend ostream & operator<<(ostream &os, const Paragraph& p) {
- return os << p.to_str();
- }
- ostream & operator<<(ostream &os) {
- return os << paragraph;
- }
- Paragraph::to_str = (return paragraph)
- #include <iostream>
- class Paragraph
- {
- public:
- Paragraph(std::string const& init)
- :m_para(init)
- {}
- std::string const& to_str() const
- {
- return m_para;
- }
- bool operator==(Paragraph const& rhs) const
- {
- return m_para == rhs.m_para;
- }
- bool operator!=(Paragraph const& rhs) const
- {
- // Define != operator in terms of the == operator
- return !(this->operator==(rhs));
- }
- bool operator<(Paragraph const& rhs) const
- {
- return m_para < rhs.m_para;
- }
- private:
- friend std::ostream & operator<<(std::ostream &os, const Paragraph& p);
- std::string m_para;
- };
- std::ostream & operator<<(std::ostream &os, const Paragraph& p)
- {
- return os << p.to_str();
- }
- int main()
- {
- Paragraph p("Plop");
- Paragraph q(p);
- std::cout << p << std::endl << (p == q) << std::endl;
- }
- ostream & operator<<(ostream &os) {
- return os << paragraph;
- }
- // T << Paragraph
- T & operator << (T & p_oOutputStream, const Paragraph & p_oParagraph)
- {
- // do the insertion of p_oParagraph
- return p_oOutputStream ;
- }
- // T >> Paragraph
- T & operator >> (T & p_oInputStream, const Paragraph & p_oParagraph)
- {
- // do the extraction of p_oParagraph
- return p_oInputStream ;
- }
- // T << Paragraph
- T & T::operator << (const Paragraph & p_oParagraph)
- {
- // do the insertion of p_oParagraph
- return *this ;
- }
- // T >> Paragraph
- T & T::operator >> (const Paragraph & p_oParagraph)
- {
- // do the extraction of p_oParagraph
- return *this ;
- }
- // OUTPUT << Paragraph
- template <typename charT, typename traits>
- std::basic_ostream<charT,traits> & operator << (std::basic_ostream<charT,traits> & p_oOutputStream, const Paragraph & p_oParagraph)
- {
- // do the insertion of p_oParagraph
- return p_oOutputStream ;
- }
- // INPUT >> Paragraph
- template <typename charT, typename traits>
- std::basic_istream<charT,traits> & operator >> (std::basic_istream<charT,traits> & p_oInputStream, const CMyObject & p_oParagraph)
- {
- // do the extract of p_oParagraph
- return p_oInputStream ;
- }
- // OUTPUT << A
- std::ostream & operator << (std::ostream & p_oOutputStream, const Paragraph & p_oParagraph)
- {
- // do the insertion of p_oParagraph
- return p_oOutputStream ;
- }
- // INPUT >> A
- std::istream & operator >> (std::istream & p_oInputStream, const Paragraph & p_oParagraph)
- {
- // do the extract of p_oParagraph
- return p_oInputStream ;
- }
- bool operator<<(const obj&, const obj&);
- ostream& operator<<(ostream&, const obj&);
Add Comment
Please, Sign In to add comment