Hi guys! My first post in this forum! Nice to meet you all :D!
Ok, straight to the point...
I want to empty a position of an array filled with objects of a class...
I have this code (it's just a part of the entire code)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
// Libreria.h
Libro * compraLibros = new Libro[2];
// Main.cpp
// AgregarLibro() is part of the Libreria class in Libreria.h
void Libreria::AgregarLibro() {
// Book 1
Libro * libro = new Libro;
libro->setLibAutor("Vargas Llosa");
libro->setLibEdicion(2010);
libro->setLibPaginas(500);
libro->setLibPrecio(20000);
catalogoLibros[0] = *libro;
delete libro;
// Book 2
libro = new Libro;
libro->setLibAutor("Pablo Neruda");
libro->setLibEdicion(1924);
libro->setLibPaginas(500);
libro->setLibPrecio(20000);
catalogoLibros[1] = *libro;
delete libro;
libro = NULL;
}
// Then I use this method to 'Buy' those books
bool Libreria::ComprarLibro(int index, int libroComprado) {
Libro * nLibro = &catalogoLibros[libroComprado];
if(nLibro != NULL) {
compraLibros[index] = * nLibro;
} else {
return false;
}
return true;
}
// And finally this method to 'return' a book to the bookstore
bool Libreria::DevolverLibro(int libroDevuelto) {
if(&compraLibros[libroDevuelto] != NULL) {
compraLibros[libroDevuelto] = NULL;
}
return true;
}
|
Well... I skipped a lot of code, since the problem is just in the DevolverLibro method (this method should 'return' a book, in other words, it should delete the specified book from the compraLibros Array).
Actually, the only one method that fails is DevolverLibro.
This is the order of the execution of methods :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
// Libreria object
Libreria * libreria = new Libreria;
// Main.cpp
// First, I add a couple of books manually :
libreria->AgregarLibro();
// I buy both of those books (so I can delete one of them later)
// The quantity of books to buy, are asked to the user by the console, but
// to show how it works, I'll pass the values directly
libreria->ComprarLibro(0, 0); // returns true, it is a boolean method
libreria->comprarLibro(1, 1); // also returns true...
// Then I try to return (delete) on of those books from the comprarLibros array
libreria->DevolverLibro(0); // Try to delete the book in the 0 index of the compraLibros array...
// Finally, I relese the memory used by 'libreria'
delete libreria;
|
And the ugly part, the error message (I almost forget it)
1 2 3 4 5
|
main.cpp: In member function `bool Libreria::DevolverLibro(int)':
main.cpp:86: error: no match for 'operator=' in '*(((Libreria*)this)->Libreria::compraLibros + (+(((unsigned int)libroDevuelto) * 16u))) = 0'
make[2]: Leaving directory `/c/path/path/.../Libreria'
Libro.h:13: note: candidates are: Libro& Libro::operator=(const Libro&)
make[2]: *** [build/Debug/MinGW-Windows/main.o] Error 1
|
I'm using NetBeans 6.9 with MingW...
Ok... I can't be more specific than that... my english is limited, so if you need more info, just ask for it...
I hope you understand me... thanks in advance :).