hello. i doing my work and facing problem in "<<" operator
i declare that method in the class

public:
    friend ostream& operator<<(ostream& out, T theList);

and in the main i am using that to print the list in this way

cout<<"First List is \n"<<list1;

but it creat error in the above line "<<list1"
Kindly give me a solution as early as possible

Thanx in Advance...

but it creat error in the above line "<<list1"

Are we supposed to telepathically extract the error from your mind?

friend ostream& operator<<(ostream& out, T theList);

This looks odd (T here should be the type of the class), but I'm not confident saying for sure since you provided so little code.

#include "stdafx.h"
#include<iostream>

using namespace std;


template<class T>
class GenericList
{
private:
    T* item;
    int current_len;
    int max_len;

public:
    GenericList(int);
    int lenght();
    void add(T new_num);
    bool full();
    void erase();
    friend ostream& operator<<(ostream& out, T theList);
};
int _tmain(int argc, _TCHAR* argv[])
{
    GenericList<int> list1(3);
    GenericList<int> list2(5);

    list1.add(4);
    list1.add(2);
    cout<<"First List is \n"<<list1;

    return 0;
}

Yes, my gut reaction was correct. The operator<< signature should be this:

friend ostream& operator<<(ostream& out, GenericList<T> theList);

You'll get an unresolved external error until the function is defined, but the main issue was you were passing the wrong type.

Okhy silly mistake i have,, anyway thanx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.