Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C/C++ - Qt Verifica di due strutture
Forum - C/C++ - Qt Verifica di due strutture

Avatar
Thejuster (Admin)
Guru^2


Messaggi: 2305
Iscritto: 04/05/2008

Segnala al moderatore
Postato alle 14:12
Domenica, 25/11/2018
Salve ragazzi, Mi sto ancora dilettando con il mio progetto Mappy
( http://www.pierotofy.it/pages/sorgenti/dettagli/19563-Mappy/ )

Ho un problema quando devo eseguire un confronto tra due strutture.
E credo che anche stavolta, mi confondo tra C# e Cpp.

dunque il codice è il seguente

Codice sorgente - presumibilmente C/C++

  1. qDebug() << m.Tiles.count();
  2.  
  3.  
  4.  
  5.     for(int i = 0; i <m.Tiles.count(); i++)
  6.     {
  7.  
  8.        MappySaver::Tile t = static_cast<MappySaver::Tile>(m.Tiles[i]);
  9.  
  10.         int duplicates = 0;
  11.         for(int j = 0; j < m.Tiles.count(); j++)
  12.         {
  13.            if(m.Tiles[i] == m.Tiles[j])  //Errore qui
  14.                duplicates++;
  15.         }
  16.  
  17.         if(duplicates > 1)
  18.             m.Tiles.removeAt(i);
  19.     }




error: no match for 'operator==' (operand types are 'MappySaver::Tile' and 'MappySaver::Tile')
           if(m.Tiles == m.Tiles[j])
                          ^

Non è che forse devo fare un override dell'operatore per verificare l'integrità?
In C# bastava fare un semplice == per verificare una struttura se combacia con l'altra.

Dovrei procedere in questo modo?

Codice sorgente - presumibilmente C/C++

  1. bool operator == (const MappySaver::Tile &tile, MappySaver::Tile &match)
  2. {
  3.  
  4.    if(tile.ID == match.ID && tile.X == match.X ecc. ecc. ecc.
  5.  
  6.   return true;
  7.  
  8. }




https://mire.forumfree.it/ - Mire Engine
C# UI Designer
PM Quote