Cześć :)
http://pastebin.com/yL5C6saA
Jak poprawić ten kod tak, aby działało <<?
0
2
przy deklaracji przyjaźni brakuje referencji, więc operator, który definiujesz nie jest zaprzyjaźniony z klasą i nie ma dostępu do wnętrza klasy.
Do tego brakuje jednego template<>
http://ideone.com/p28ifa
1
#include <iostream>
using namespace std;
template<class T> class Klasa
{
private:
int a;
T rElement;
public:
Klasa(T rElement,int a):a(a),rElement(rElement) {}
Klasa(int a):a(a),rElement(T()) {}
friend ostream &operator<<(ostream &out,const Klasa &right)
{
return out<<right.rElement;
}
};
int main()
{
Klasa<int> obiekt0(2,7),obiekt1(9,7);
cout<<obiekt0;
return 0;
}
2
friend ostream& operator<<<>(ostream& out, const Klasa<T>& right);