hi
Im having problems with class templates and user defined objects
ie:
Code:
#include <iostream>
#include <stdlib.h>
using namespace std;
#include "plantpila1.h"
int main()
{
double arregloDouble[5]={1.1,2.2,3.3,4.4,5.5};
Pila<double>doublePila(arregloDouble,5);
doublePila.imprimir();
int arregloInt[3]={1,2,3};
Pila<int>intPila(arregloInt,3);
intPila.imprimir();
//user defined object
Marciano arregloMarciano[3]={Marciano(" marte "),Marciano(" venus "),Marciano(" jupiter ")};
Pila<Marciano>marcianoPila(arregloMarciano,3);
marcianoPila.imprimir();
cout << endl;
system("PAUSE");
return 0;
}
//heres the class definition
#ifndef PLANTPILA1_H
#define PLANTPILA1_H
template<class T>
class Pila{
public:
Pila(T *,int = 10);//10 is Pila size
void imprimir();
private:
T *ptr;
int tamanioPila;
};
//member funcions for Pila
//constructor
template<class T>
Pila<T>::Pila(T *arr,int s)
{
tamanioPila = s > 0? s : 10;
ptr = arr;
}
//print the array
template <class T>
void Pila<T>::imprimir()
{
for(int i = 0; i < tamanioPila; i++)
cout << ptr[i] << ' ';
}
ok in the book that im studing says that when you use not native objects(int,float,etc) you need to do that:
template<>
class Pila<Marciano>{
//class body
};
but he dont says where or how i use this . how use this syntaxis?
plase can somebody help me?
i need this template can work with user defines Marciano.
please excuse my poor english
if you need to see Marciano class i can paste it later