The template declaration:
Code:
template<class TG> class CMatriz
{
public:
CMatriz(unsigned int j,unsigned int k=1);
~CMatriz();
CMatriz<TG> T(void);
void inserta(unsigned int j,unsigned int k,const TG &op);
TG obten(unsigned int j,unsigned int k) const;
CMatriz<TG> operator=(const CMatriz<TG> &op);
friend ostream &operator<<(ostream &os,const CMatriz<TG> &op);
protected:
void Destruye();
void Crea(unsigned int j,unsigned int k);
unsigned int m_reng,m_cols;
vector<TG> m_matriz;
};
Problem when calling the function:
Code:
template<class TG>
CMatriz<TG> CMatriz<TG>::T(void)
{
unsigned int i,j;
CMatriz<TG> transpuesta(m_cols,m_reng);
for(i=0;i<m_reng;i++)
for(j=0;j<m_cols;j++)
transpuesta.inserta(j,i,obten(i,j));
return transpuesta;
}
Code executed:
Code:
CMatriz<int> matriz(4),matriz2(2);
matriz.inserta(0,0,0);
matriz.inserta(1,0,1);
matriz.inserta(2,0,2);
matriz.inserta(3,0,3);
cout << matriz;
cout << matriz.T();
the output is:
The output I'm expecting is "0 1 2 3" (I do get this output if I do cout << transpuesta within CMatriz<TG>::T(void) right before return transpuesta)
The object put in place of matriz.T() is supposed to be a copy of transpuesta but m_matriz is not being copied.
Note: ~CMatriz() is empty.
Any hints?