I've been writing code just in main.cpp, but I wish to clean everything up and separate files into header as well as a definitions source file.
I understand the concept(to a small extent)of the #include insofar as it basically copy/pastes the stuff(to put it simply) - if this is incorrect, do correct my ignorance.
I keep getting this: "multiple definition of 'user_input' ".
So here is my 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
|
#include <iostream>
#include "declarations.h"
int main()
{
user_input = "";
std::cout<<"Welcome to your new life. If you are not familiar with text-based games, that's okay -- as long as you can read. If you can read, everything else will fall into place. \n"<<std::endl;
std::cout<<"Our tutorial will become larger as the game develops, as will the gaming environment, so bear with us as we continue providing updates and items to the game. \n"<<std::endl;
while(user_input != "start")
{
std::cout<<"Tye the word \"start\" to begin: ";
std::getline(std::cin, user_input);
if(user_input == "start")
{
Character_Setup();
//user_input = "";
}
else
std::cout<<"You have entered an invalid response. Please type \"start\" to begin.\n";
}
}
|
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
|
//declarations.h header file
#ifndef _DECLARATIONS_H_INCLUDED
#define _DECLARATIONS_H_INCLUDED
//#include "definitions.cpp"
std::string user_input;
void Character_Setup();
struct Player_Character
{
std::string name;
int age;
std::string race;
std::string class_type;
std::string profession;
struct attributes
{
int Stamina_att;
int Strength_att;
};
};
#endif
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
//definitions.cpp
#include <iostream>
#include "declarations.h"
void Character_Setup()
{
std::string user_input_char_setup;
int completion;
while(completion=0)
{
std::cout<<"What would you like your character name to be?\n";
//std::getline(std::cin, user_input_char_setup);
}
}
|
My error comes on the beginning brace of int main on my main.cpp -- line 8.
Now, I've changed the '#includes' around and have received various errors such as 'not defined' or 'redefinition of 'void character_setup'.
I've been trying to understand this for awhile now; I can't so I'm asking the community to maybe explain the functionality of this in a way that I'll be able to fix it because I understand it rather than fix it because I know I'm supposed to put 'this' here or 'that' there..if that makes any sense.
Thank you in advance.
To add, I added variables like 'user_input_char_setup' just to test some things to fix the problem. So they will seem out of place because they are.