I have tried and tried and googled and googled and everything I have found and tried do not work :(
The files contents are too long to post here, so I just posted links to download them, the header file didn't work when making it available for download, so I am posting the source here.
/* Filename: roleplay.h
* Devs: Micah Butler (princessjinifer)
* Created: 5/10/2010
* A text based roleplaying game that I wrote on a boring car trip home from Grandma's house ^_^
* v.0 (first build)
*/
//#ifndef ROLEPLAY_H
#define ROLEPLAY_H
#include <cstdlib> // included for the 'system("clear")'
usingnamespace std; // people say not to add this one, I don't want to type std:: in front of all my things, too much coding :D
string character_name; // at the beginning when they choose their character name, and used later on probably for saved games.*/
string what_to_do; // when the user is asked what they want to do, this is used for their input.
string are_you_sure;
int area_number; // this tells the plan_of_action which area you are in
int gold_amount = 0; // for handling how much gold the player has :)
void game_beginning (); // where the game actually begins
void game_beginning_part2 (); // after the 'plan_of_action' function
void plan_of_action (); // what is your plan of action?
void the_shop (); // After the user enters the shop, this is the function that takes effect
void the_hotel (); // This is the various hotels that the user can go to.
void the_fence (); // the electric fence when you first start off
void the_help (); // shows you the help, I will most likely take this one out
void wanting_to_quit (); // after the user types quit or exit it will take them here asking if they are sure.
void talk_to_phil (); // have a conversation with the first shop owner
void the_shop_part2 (); // where you buy/sell/check prices
void leave_the_building (); // after leaving any building
void the_shop_2 (); // after you talk to phil and use the shop
//void available_actions (); // I am not sure if I will use this one or not, probably not.
and after compiling with "g++ -c filename" I linked them with "g++ roleplay.o shops.o" and it spits this out at me:
micah@micah-N120:~/C/roleplay$ g++ roleplay.o shops.o
shops.o:(.bss+0x0): multiple definition of `character_name'
roleplay.o:(.bss+0x0): first defined here
shops.o:(.bss+0x4): multiple definition of `what_to_do'
roleplay.o:(.bss+0x4): first defined here
shops.o:(.bss+0x8): multiple definition of `are_you_sure'
roleplay.o:(.bss+0x8): first defined here
shops.o:(.bss+0xc): multiple definition of `area_number'
roleplay.o:(.bss+0xc): first defined here
shops.o:(.bss+0x10): multiple definition of `gold_amount'
roleplay.o:(.bss+0x10): first defined here
collect2: ld returned 1 exit status
Where do I put the strings and ints? I thought in the header, but that didn't work :( any help please? I will answer any question asked if I can :)
//In header:
extern T global;
//In one, AND ONLY ONE, source:
T global;
//If you need to, you may initialize it to something or pass parameters to the constructor
//on the above line.
Okay, I took them out and put them in roleplay.cpp, and it give me errors for them missing in the "g++ -c shops.cpp", if I add them to both, that is just like having them in the header, on my other program, I put all my variables in the header, but that program is just a header and a source file, no others...
Globals are variables declared in global scope (not inside any function).
Do what helios said. (or find a better structure for your program that doesn't rely on globals at all)
That worked ^_^ Thank you so much! I have tried and tried to do multiple files, and none of the sites I saw showed the source with the extern OR I didn't notice them...