Thread: Ambiguous operator?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Ah yes, from one problem to the other. Template friends are just a pain; this solves the ambiguous operator, but fails to make the friend declaration work. Wonderful, that's what I call it.
    Good thing I decided to use an easier approach.

    I'm not even going to bother with this approach anymore >_<

    EDIT:
    Actually, this works!
    Code:
    #include <iterator>
    #include <iostream>
    
    template<typename T, bool ReadOnly> class buffered_stream_iterator;
    
    template<typename T, bool ReadOnly, typename T2> T2& operator += (T2& lhs, const buffered_stream_iterator<T, ReadOnly>& rhs);
    
    template<typename T, bool ReadOnly>
    class buffered_stream_iterator:
    	public std::iterator<std::random_access_iterator_tag, T>
    {
    public:
    	template<typename, bool, typename T2> friend T2& operator += (T2& lhs, const buffered_stream_iterator<T, ReadOnly>& rhs);
    
    private:
    	int m_Test;
    };
    
    template<typename T, bool ReadOnly, typename T2> T2& operator += (T2& lhs, const buffered_stream_iterator<T, ReadOnly>& rhs)
    {
    	std::cout << rhs.m_Test;
    	return lhs;
    }
    
    int main()
    {
    	buffered_stream_iterator<wchar_t, false> Test;
    	int n = 0;
    	n += Test;
    	return 0;
    }
    Last edited by Elysia; 07-27-2009 at 02:44 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 07:05 AM
  3. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  4. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM
  5. <list>
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 02-24-2002, 04:07 PM