Jump to content
  • Advertisement
Sign in to follow this  
metrix

intercepting ostream manipulators

This topic is 4321 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, I'm hoping one of you C++ pro's will know the answer to this. Consider the following:
class myostr : public std::ostream
{
     public:
          ...

          myostr & operator << (std::ostream & (*f)(std::ostream &))
          {
               if( f == std::endl )
                    // do something here
               return *this;
          }
     private:
          ...
};

What is wrong with that if statement? In VC++ .NET 7 it compiles clean. In XCode 2.4 (?? GCC some version of other ??) I get the following compilation error: error: assuming cast to type 'std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&)' from overloaded function I'm assuming because the endl is a function template and not specialized, so how can the compiler made comparisons to f? Thanks, metrix

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by metrix
I'm assuming because the endl is a function template and not specialized,
so how can the compiler made comparisons to f?


Cast the expression std::endl to the appropriate type before doing the comparison. This will force the selection of one of the overloads, as determined by the type you are casting to.

Share this post


Link to post
Share on other sites
Thanks for the reply.
Can you perhaps show me how to do this?
I have tried various casts, but with the template
syntax I'm quite lost.

metrix

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!