Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/10/2015, 05:00
Avatar de giuli956
giuli956
 
Fecha de Ingreso: noviembre-2012
Mensajes: 149
Antigüedad: 11 años, 6 meses
Puntos: 1
Patron prototype: como implementarlo

Bueno, quise implementar el patron prototype con 2 prototipos de tv que hereda del prototipo TV. PrototipoLED y prototypePLASMA, pero no funciona.
Obtengo el error 101 no matching function for call to `prototipoLED::prototipoLED(prototipoTV)' y luego muestra los parametros del constructor, es el tipico error de los atributos en el constructor pero no se como se resuleve...

Aqui el codigo

Código C++:
Ver original
  1. #include <iostream>
  2. using namespace std;
  3. class prototipoTV{
  4.  
  5.       protected:
  6.       string marca;
  7.       string modelo;
  8.       string color;
  9.       int resvert;
  10.       int reshori;
  11.       string TEC;
  12.       int brillomax;
  13.       int garantia;
  14.       public:
  15.              
  16.       prototipoTV(string marcaTV,string modeloTV,string colorTV,string TECTV,
  17.       int resvertTV,int reshoriTV,int brillomaxTV,int garantiaTV){
  18.              marca=marcaTV;
  19.              modelo=modeloTV;
  20.              color=colorTV;
  21.              TEC=TECTV;
  22.              resvert=resvertTV;
  23.              reshori=reshoriTV;
  24.              brillomax=brillomaxTV;
  25.              garantia=garantiaTV;
  26.       };
  27.       virtual prototipoTV clonar();
  28.      
  29.       void setMarca(string marcaTV){this->marca=marcaTV;};
  30.       void setModelo(string modeloTV){this->modelo=modeloTV;};
  31.       void setColor(string colorTV){this->color=colorTV;};
  32.       void setTEC(string TECTV){this->TEC=TECTV;};
  33.       void setResvert(int resvertTV){this->resvert=resvertTV;};
  34.       void setReshori(int reshoriTV){this->reshori=reshoriTV;};
  35.       void setBrillomax(int brillomaxTV){this->brillomax=brillomaxTV;};
  36.       void setGarantia(int garantiaTV){this->garantia=garantiaTV;};
  37. };      
  38. class prototipoLED:public prototipoTV{
  39.       private:
  40.               int garantia;
  41.       public:
  42.            
  43.              prototipoLED::prototipoLED(string marcaTV,string modeloTV,string colorTV,string TECTV,
  44.              int resvertTV,int reshoriTV,int brillomaxTV,int garantiaTV):prototipoTV(marcaTV,modeloTV,
  45.              colorTV,TECTV,resvertTV,reshoriTV,brillomaxTV,garantiaTV){
  46.                                                                
  47.                                                                        };
  48.              void getTipoTV(){
  49.                          cout<<("soy un LED")<<endl;
  50.                          };
  51.              prototipoTV clonar(){
  52.                          //prototipoLED *LED2= new prototipoLED("A","A","A","A",1,1,1,1);
  53.                          prototipoTV *LED2= new prototipoLED(*this);
  54.                          /*LED2->setMarca(this->marca);
  55.                          LED2->setBrillomax(this->brillomax);
  56.                          LED2->setColor(this->color);
  57.                          LED2->setModelo(this->modelo);
  58.                          LED2->setReshori(this->reshori);
  59.                          LED2->setResvert(this->resvert);
  60.                          LED2->setTEC(this->TEC);
  61.                          LED2->setGarantia(this->garantia);*/
  62.                          return *LED2;
  63.                          };
  64.       };
  65. class prototipoPLASMA:public prototipoTV{
  66.       private:
  67.               int garantia;
  68.       public:
  69.          
  70.              prototipoPLASMA::prototipoPLASMA(string marcaTV,string modeloTV,string colorTV,string TECTV,
  71.              int resvertTV,int reshoriTV,int brillomaxTV,int garantiaTV):prototipoTV(marcaTV,modeloTV,
  72.              colorTV,TECTV,resvertTV,reshoriTV,brillomaxTV,garantiaTV){
  73.                                                                    
  74.                                                                        };
  75.              void getTipoTV(){
  76.                          cout<<("soy un PLASMA")<<endl;
  77.                          }
  78.              prototipoTV clonar(){
  79.                          prototipoPLASMA *PLASMA2= new prototipoPLASMA("samsung","dff","negro","IPS",1280,720,12,24);
  80.                          PLASMA2->setMarca(this->marca);
  81.                          PLASMA2->setBrillomax(this->brillomax);
  82.                          PLASMA2->setColor(this->color);
  83.                          PLASMA2->setModelo(this->modelo);
  84.                          PLASMA2->setReshori(this->reshori);
  85.                          PLASMA2->setResvert(this->resvert);
  86.                          PLASMA2->setTEC(this->TEC);
  87.                          return *PLASMA2;
  88.                          };
  89.       };
  90. class Cliente{
  91.      
  92.      
  93.    
  94.     public: static void obtenerTVs(){
  95.             prototipoLED *primerLED=new prototipoLED("samsung","dff","negro","IPS",1280,720,12,6);
  96.             prototipoPLASMA *primerPLASMA= new prototipoPLASMA("samsung","dff","negro","IPS",1280,720,12,6);
  97.             prototipoLED *listaLED[10];
  98.             prototipoPLASMA *listaPLASMA[10];
  99.             for (int x=0;x<10;x++){
  100.                        // cout<<primerLED->clonar()<<endl;  
  101.                         listaLED[x]= (prototipoLED) primerLED->clonar();
  102.                      //  listaPLASMA[x]=(prototipoPLASMA) primerPLASMA->clonar();
  103.                      
  104.                        
  105.                        listaLED[x]->getTipoTV();
  106.                    
  107.                                      };
  108.            
  109.                             };
  110.       };
  111. int main(){
  112.    
  113.     Cliente::obtenerTVs();
  114.        
  115.            system("pause");
  116.            return 0;
  117.            };

estoy probando primero con LEd para luego hacer PLASMA.
Saludos