Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2012
    Messaggi
    28

    [C++] p.o.o. problemi ridefinizione operatori

    codice:
    #ifndef COMPONENTE_H_INCLUDED
    #define COMPONENTE_H_INCLUDED
    #include<iostream>
    using namespace std;
    #include <string>
    enum TIPO{FORCELLA=0,MOTORE,GOMMA,STERZO};
    class Componente
    {
        private:
        TIPO tipo;
        string colore;
        double costo;
        string modellos;
    
        public:
        Componente();
        Componente(TIPO t,string co,double c,string m)
        {
            tipo=t;
            colore=co;
            costo=c;
            modellos=m;
        }
        TIPO getTipo() const
        {
            return tipo;
        }
        string getColore() const
        {
            return colore;
        }
        double getCosto() const
        {
            return costo;
        }
        string getModello() const
        {
            return modellos;
        }
        Componente& operator=(const Componente& a)
        {
            tipo=a.tipo;
            modellos=a.modellos;
            colore=a.colore;
            costo=a.costo;
            return *this;
        }
        bool operator!=(const Componente& c)
        {
            if(tipo!=c.tipo && colore!=c.colore && costo != c.costo && modellos != c.modellos)
                return true;
            return false;
        }
        bool CompatibileCon(string mod)
        {
            if(modellos==mod)
            {
                return true;
            }
            return false;
        }
        friend ostream& operator<<(ostream& out,const Componente& c)
        {
            out<<c.tipo<<" "<<c.modellos<<" "<<c.colore<<" "<<c.costo<<endl;
            return out;
        }
    
    
    };
    
    
    
    
    #endif // COMPONENTE_H_INCLUDED
    codice:
    #ifndef AUTOMOBILE_H_INCLUDED
    #define AUTOMOBILE_H_INCLUDED
    #include<iostream>
    #include<list>
    using namespace std;
    #include"Componente.h"
    class Automobile
    {
        private:
        list<Componente> componenti;
        string modello;
    
        public:
        Automobile();
        Automobile(const Automobile& a)
        {
            componenti=a.componenti;
        }
        Automobile& operator=(const Automobile& a)
        {
            componenti=a.componenti;
            return *this;
        }
        bool operator==(const Automobile& a)
        {
            if(a.componenti.size() != componenti.size())
            {
                return false;
            }
            list<Componente>::const_iterator jt=componenti.begin();
            for(list<Componente>::const_iterator it=a.componenti.begin();it!=a.componenti.end();it++)
            {
                if(*jt != *it)
                {
                    return false;
                }
                jt++;
            }
            return true;
        }
        double costo()
        {
            double sum = 0;
            for( list<Componente>::iterator i= componenti.begin(); i!= componenti.end(); i++)
                    sum += i->getCosto();
            return sum;
        }
        bool aggiungiComponente(Componente c)
        {
            if(!c.compatibileCon(modello))
                return false;
            for( list<Componente>::iterator i=componenti.begin(); i!= componenti.end(); i++)
                if(!i->compatibileCon(c))
                    return false;
            componenti.push_back(c);
            return true;
        }
    
    };
    Mi da questi errori:

    C:\Users\FabriWebmaster\Desktop\Oggetti\CLASSAUTOM OBILE\Automobile.h||In member function 'bool Automobile:perator==(const Automobile&)':|
    C:\Users\FabriWebmaster\Desktop\Oggetti\CLASSAUTOM OBILE\Automobile.h|33|error: passing 'const Componente' as 'this' argument of 'bool Componente:perator!=(const Componente&)' discards qualifiers|
    C:\Users\FabriWebmaster\Desktop\Oggetti\CLASSAUTOM OBILE\Automobile.h||In member function 'bool Automobile::aggiungiComponente(Componente)':|
    C:\Users\FabriWebmaster\Desktop\Oggetti\CLASSAUTOM OBILE\Automobile.h|50|error: 'class Componente' has no member named 'compatibileCon'|
    C:\Users\FabriWebmaster\Desktop\Oggetti\CLASSAUTOM OBILE\Automobile.h|53|error: 'class Componente' has no member named 'compatibileCon'|
    ||=== Build finished: 3 errors, 0 warnings ===|

    dove sbaglio??

  2. #2
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,480
    E'

    CompatibileCon

    con l'iniziale maiuscola e poi in

    CompatibileCon(c)

    c non è una stringa.
    No MP tecnici (non rispondo nemmeno!), usa il forum.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.