Показать сообщение отдельно

  #2  
Старый 21.05.2008, 18:08
Forcer
Постоянный
Регистрация: 12.04.2007
Сообщений: 413
С нами: 10042776

Репутация: 275
По умолчанию

изменил(добавил код) структуру:
Код:
struct info {    
    int RegCode;
    char FIO[25];
    char Address[255];
    int INN;
    
    bool equals(const info& obj) {
        return ( RegCode == obj.RegCode         && 
                 !strcpy(FIO, obj.FIO)          && 
                 !strcpy(Address, obj.Address)  && 
                 INN == obj.INN 
                ) ;
    }
};
Код:
info& operator[](int i) {
        if( i < 0 || i >= size ) {
            std::cerr << "ArrayOutOfBounds" << std::endl;
        } else {
            return *(a[i]);
        }
    }
    
    bool operator==(const info** right) const {
        info* curInfo = 0;
        for(int i = 0; i < counter; ++i) {
            curInfo = a[i];
            if( !curInfo->equals(*(right[i])) ) {
                return false;
            }
        }
    }
    
    // предполагается что массивы одинаковых размеров
    const info** operator=(const info** right) {
        for( int i = 0; i < counter; ++i ) {
            if( a[i] != 0 ) {
                delete a[i];
            }
            
            a[i] = new info();
            a[i]->RegCode = right[i]->RegCode;
            a[i]->INN = right[i]->INN;
            strcpy(a[i]->FIO, right[i]->FIO);
            strcpy(a[i]->Address, right[i]->Address);
        }
        
        return (const info**)a;
    }
    
    void operator!() {
        if(a == 0) {
            return;
        }
        
        for( int i = 0; i < counter; ++i ) {
            if( a[i] != 0 ) {
                delete a[i];
            }
        }
        
        delete []a;
    }
 
Ответить с цитированием