#include <iostream>
usingnamespace std;
template<typename T>
class complex{
T r;
T i;
public:
complex<T>():r(0),i(0){};
complex<T>(T a):r(a),i(0){};
complex(T a,T b):r(a),i(b){};
complex<T> (const complex<T>& a){ //copy constructor
r = a.r;
i = a.i;
}
complex<T>& operator=(const complex<T> & a){ // copy assignament;
r = a.r;
i = a.i;
return *this;
}
constint get_r(){ //get real part
int a = r;
return a;
}
constint get_i(){ //get imaginarium part
int a = i;
return a;
}
template<typename T>
friend ostream& operator<<(ostream & os,complex<T>& a);
////here is the error...if i do the same with N instead of T, It works.
///but i dont know the reason
};
template<typename T>
ostream& operator<<(ostream& os, complex<T>& a){
os<<"Parte real "<<a.get_r()<<" "<<"Parte imaginaria "<<a.get_i()<<endl;
return os;
}
int main(){
cout<<"TESTEO DE CONSTRUCTOR Y COPY,ASSIGNAMENT, MOVE..ETC"<<endl;
complex<int> a;
complex<int> b(1);
complex<int> c(4,5);
complex<int> t(a);
a = c;
cout<<c<<endl;
complex<char> rojo;
complex<char> azul(99,87);
cout<<rojo<<azul<<c;
}
this code launch an error that is
Your example is equivalent to `the extrovert' on the previous link.
In this case the `operator<<' have access to all complex instantiations. By instance, you could operate with `complex<double>' when you are printing a `complex<char>'
It's quite promiscuous.
(note the example in `Taking advantage of the extrovert')
> I dont understande properly what you mean about a meaning...
> It's because both typenames are declared in the same scope and then there's a conflict??
Yes, it's like saying