In your ClassRooms.cpp:
rooms = new ClassRoom(nrooms);
Shouldn't this be
rooms = new ClassRoom[nrooms]
(square brackets)?
When I fix that, I'm just left with two more errors:
classrooms.cpp: In member function 'std::string ClassRooms::findRoom(int)':
classrooms.cpp:22:44: error: taking address of temporary [-fpermissive]
return &rooms[i].getRoomNumber();
^
classrooms.cpp:22:44: error: could not convert '& ClassRoom::getRoomNumber()()'
from 'std::string* {aka std::basic_string<char>*}' to 'std::string {aka std::basic_string<char>}'
classrooms.cpp: At global scope:
classrooms.cpp:27:25: error: definition of implicitly-declared 'ClassRooms::~ClassRooms()'
ClassRooms::~ClassRooms()
^ |
Now, the first two errors are in your
ClassRooms::findRoom function. I'm not exactly sure what you're trying to return from this function, but here are my two guesses:
1. You're trying to return the room number (as a
string).
In this case, you need to get rid of the
& in
return &rooms[i].getRoomNumber();
, since the
& will return the address of the copy of the
roomNum variable returned by
getRoomNumber, not the actual
string itself.
I would also change your
return NULL;
to something like
return string();
or something (to return an empty string), or otherwise return some kind of
string representing a "room not found" situation, since typically,
NULL is just used for pointers and not for
strings like what you have here. (It still compiles either way.)
2. You're trying to return a pointer to the
roomNum variable holding the room number.
In this case, your
getRoomNumber() function currently returns a temporary copy of
roomNum, so that's not what you want, so you'll need to change
string ClassRoom::getRoomNumber()
to either
string& ClassRoom::getRoomNumber()
or
const string& ClassRoom::getRoomNumber()
, depending on whether or not you want to be able to change the room number (my guess is that you don't, so you'll want to use the latter declaration).
Also, you'll have to change
string ClassRooms::findRoom(int seats)
to either
string* ClassRooms::findRoom(int seats)
or
const string* ClassRooms::findRoom(int seats)
, depending on which one of the two you picked for
ClassRoom::getRoomNumber().
For the last error, you just forgot to declare your destructor for
ClassRooms in your header file.
Hopefully that made sense.