Code:
#include <iostream>
using namespace std;
template <class TIP>
class Konstrukcija
{
TIP *niz;
int _trenutno; // trenutna poz. u nizu
int _max; // maksimalno elemenata
public:
Konstrukcija()
{
_trenutno = 0;
_max = 10;
niz = new TIP[_max];
}
//bez destruktora i sl...
void dodaj(TIP obj)
{
niz[_trenutno] = obj;
++_trenutno;
}
friend ostream &operator<< <>(ostream &, Konstrukcija<TIP> &); // <<<<<<<<<<<<<<<<<<<<
// upitno je kada stavim <> , ali i ovako ne radi
};
template <class TIP>
ostream &operator<<(ostream &OUT, Konstrukcija<TIP> &obj)
{
for(int i=0; i<obj._trenutno; i++)
OUT << obj._niz[i];
return OUT;
}
int main()
{
Konstrukcija<int> stub;
stub.dodaj(2);
stub.dodaj(10);
cout << stub;
system("pause>0"); return 0;
}
#include <iostream>
using namespace std;
template <class TIP>
class Konstrukcija
{
TIP *niz;
int _trenutno; // trenutna poz. u nizu
int _max; // maksimalno elemenata
public:
Konstrukcija()
{
_trenutno = 0;
_max = 10;
niz = new TIP[_max];
}
//bez destruktora i sl...
void dodaj(TIP obj)
{
niz[_trenutno] = obj;
++_trenutno;
}
friend ostream &operator<< <>(ostream &, Konstrukcija<TIP> &); // <<<<<<<<<<<<<<<<<<<<
// upitno je kada stavim <> , ali i ovako ne radi
};
template <class TIP>
ostream &operator<<(ostream &OUT, Konstrukcija<TIP> &obj)
{
for(int i=0; i<obj._trenutno; i++)
OUT << obj._niz[i];
return OUT;
}
int main()
{
Konstrukcija<int> stub;
stub.dodaj(2);
stub.dodaj(10);
cout << stub;
system("pause>0"); return 0;
}
Uspijem koristiti program s funkcijom clanicom koja koja je tipa void i slicna funkciji operatora<<, ali zasto preklopljeni operator ne radi???