Thread: Templates

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    417

    Templates

    I can't remember how to do this...

    Say you have an operator overload that usually looks like this:

    template <typename UnknownType>
    any operator <<(const any & lhs, const UnknownType & rhs)

    but you want a explicit (I think thats the right word :-)) version of it like this that does something different:

    istream& operator <<(ostream & is, any & operand)

    How do you do this when you know for sure you want an ostream?

    I thought it would be

    template <ostream>
    ostream& operator <<(ostream & os, const any & operand)

    However, it really isn't liking this, as now there are three << overloads:

    Code:
    template <ostream>
    	ostream& operator <<(ostream & os, const any & operand)
    Code:
    	template <typename UnknownType>
    	any operator <<(const any & lhs, const UnknownType & rhs)
    Code:
    	template <typename UnknownType>
    	UnknownType operator <<(const UnknownType & lhs,const any & rhs)
    How do I get it to run a different overload if parameter one is an ostream and parameter two is an any?

    I also need it to be able to have parameter one be UnknownType and parameter two be any... the reverse.
    Last edited by Trauts; 05-14-2003 at 04:52 PM.

  2. #2
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167
    No idea.
    AIM: MarderIII

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Which function template generates errors?

    template <>
    ostream& operator <<(ostream & os, const any & operand)

    Kuphryn

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    417
    I think the problem is the constructor for the any takes any type... hence the name.

    I'll see if making it explicit fixes it, if so, we know what to do.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Templates from DLL or static library problem
    By mikahell in forum C++ Programming
    Replies: 2
    Last Post: 01-01-2008, 01:49 AM
  2. Questions about Templates
    By Shamino in forum C++ Programming
    Replies: 4
    Last Post: 12-18-2005, 12:22 AM
  3. templates and inheritance problem
    By kuhnmi in forum C++ Programming
    Replies: 4
    Last Post: 06-14-2004, 02:46 AM
  4. When and when not to use templates
    By *ClownPimp* in forum C++ Programming
    Replies: 7
    Last Post: 07-20-2003, 09:36 AM