And is this the best/cleanest way of coding?
well, its one way.
and about par for a first stab at it. IE we all started out that way. <g>.
for a small game, it would get the job done.
first thing i notice, you have a "game loop" (display contents, get and process input) for each room.
games typically have just one "game loop". in your case it might look something like:
while (! quitgame)
1. list contents of current room
2. based on current room, get and process user input
So far, in main() I have an instance of Inventory called inventory and make the objects false, then room1(); But (of course), when I go to room1() inventory doesn't exist. Is there a way I can reach and modifying in them globally? without passing them through the function name? (say room1(key1))
someone else here will have to help you with that, i stick mostly to c syntax myself. but don't worry, you'll get lots of suggestions. there tend to be many ways to skin a cat using c++ syntax.
but from an oo point of view...
off the top off my head, i'd say a room is a class, with data like a list of objects in the room, and methods like display_list and process_input.
then your game loop would look something like:
while (! quitgame)
room[current_room].display_list
room[current_room].process_input
where room[] is a list of room objects
and
current_room is a global of some sort, used by the game loop, but changed by the process_input methods when the player goes though a door. its is, in essence, a global "game state" variable, where each room is a "game state".
if keys are your only inventory item,you might use a "list of keys" object with 3 Booleans for keys 1,2, and 3, perhaps as an array BOOLEAN[3] or int[3], or BYTE[3]), and methods like add_key(key_num), remove_key(key_num) etc.
then your room[0].process_input method would call keylist.add_key(1) when they found the key to the next room. and perhaps keylist.addkey[0] when they find the key to the room they start in (so they can go back).
note that in applying oo design here, i'm thinking more in terms of data structures and the methods that use them (room contents data structure, inventory list data structure), and less in terms of "objects" (room, key).
from an objects standpoint, one would think "a room is an object", probably leading to a "list of room objects" data structure. but one would also think "a key is an object", probably leading to a list of keys objects, which is probably overkill. i mean, a class with one Boolean, and two methods, set, and clear? PLEEEZE! talk about OVER-ENGINEERING! <g>.
in the long run, you'll find the KISS principle (Keep It Stupid-Simple, IE so simple a total idiot could get it) to be a good friend when coding. it makes code easy to read, makes code easy to write, and often tends to be what runs the fastest.