I am a beginner in C++.I am trying to overload my cout operator for my template. However, it does not accept the way that i used for my classes' operators.So, i am here to learn your thoughts.
This is my header
#include <iostream>
using namespace std;
template <class T>
class Set{
private:
T *data;
int index;
public:
Set() :index(0){
data=new T[100];
}
void addElement(T t){
int x=0,i;
for(i=0;i<index;i++){ // to add element
if(data[i]==t){
cout<<"This element ("<<t<<") cannot be added since it is already in the elements"<<endl;
x=1;
}
}
if(x!=1)data[index++]=t;
}
ostream& operator<<(ostream& s,const Set<T1>& b){ //place in which i want to overload
s<<"Printed";
return s;
}
};
This is my main
#include <iostream>
#include<string.h>
using namespace std;
#include "Stack.h"
int main(){
Set<int> x1;
x1.addElement(4);
x1.addElement(7);
cout<<x1;
return 0;
}