I'm doing a practical assignment for university and I've run into a problem. I've got a class that declares this method:
bool graficarTablero(const Tablero *&tablero, const string &nombreArchivo);
I want to pass a pointer to an object Tablero by constant reference. If I call that function like, say for example:
ArchivoGrafico *grafico = new ArchivoGrafico;
if(grafico->graficarTablero(tablero, ARCHIVO_GRAFICO)){ ...
...I get compilation errors. Ok, I won't detail the error I get cause I think I already found a solution for it, by replacing the method header for:
bool graficarTablero(Tablero* const& tablero, const string &nombreArchivo);
Now that SEEMS to work (at least it compiles now), but what I'd like to know is the reason why the first declaration doesn't work while the second does. Well, more importantly what I'd really like to know if they actually mean the same thing (pointer to object by constant reference).
Well, thanks for your answer.
EDIT 1: What I'd like to do is to avoid passing by value. Well, I know it's not really an expensive operation, but is there really no way to use the same pointer with the promise that it won't be modified in any way?
Thanks.
EDIT 2: Sorry, I didn't read Jerry Coffin's answer carefully enough. Yes, that's what I was looking for. It's not that I really have to do that, but I may find that little optimization useful some day.