Good Day Folks!

I'm having a difficult time getting this operator overloading function to work. I have try various syntax to get it to work.
When I run the following code I get this compile error.

g++ -Wall hmw6.cpp -o driver
set.h: In instantiation of `correaj::set<int>':
hmw6.cpp:9: instantiated from here
set.h:91: error: `operator<<' not defined

Compilation exited abnormally with code 1 at Sun Mar 28 14:35:09

What could be the problem? Please help if you can.

Johnnie

#ifndef CORREAJ_SET_H
#define CORREAJ_SET_H
#include <iostream>
#include <string>
#include <cstdlib>   // Provides NULL and size_t and NULL
#include "node.h"   // Provides node class

namespace correaj
{
    template <class Item>
    class set
    {
    public:
        // TYPEDEFS
	typedef std::size_t sizeType;
	typedef Item valueType;
	typedef nodeIterator<Item> iterator;
	typedef constNodeIterator<Item> constIterator;
	
	//FRIEND FUNCTIONS
	friend std::ostream& operator << <Item> ( std::ostream& outs, const set<Item>& source );

----------------------------------------------------------------------------------
IMPLEMENTATION FILE

#include "node.h"   // Provides node class
#include "set.h"
#include "hw6functions.h"

namespace correaj
{
    template <class Item>
    std::ostream& operator << <Item> ( std::ostream& outs, const set<Item>& source )
    {
	set<Item>::constIterator<Item> position;
	
	outs = " { ";
	for( position = source.begin( ); position != source.end( ); ++position )
	{
	    if ( position->link( ) != NULL )
		outs = ( *position ) + ", ";
	    else
		outs = ( *position );
	}

	return outs;
    }

Edited 6 Years Ago by correaj: n/a

This worked when I changed a few things.

template < typename T >
	friend std::ostream& operator << ( std::ostream& outs, const set<T>& source ); 

 template <typename T>
    std::ostream& operator << <Item> ( std::ostream& outs, const set<T>& source )
    {
	set<Item>::constIterator<Item> position;
	
	outs = " { ";
	for( position = source.begin( ); position != source.end( ); ++position )
	{
	    if ( position->link( ) != NULL )
		outs = ( *position ) + ", ";
	    else
		outs = ( *position );
	}

	return outs;
    }
This article has been dead for over six months. Start a new discussion instead.