Hello again all, So I've been doing a more organized re-write of a text adventure program I've been working on and putting variables into structures, but I've had some serious difficulty accessing the variables within them.
For example, when I was trying to make references to the variables within the structure:
Code:
struct attributes {
int name[256];
int race;
int health_stat;
};
Which I defined individually in main as:
Code:
attributes player_attributes;
I created a case switch:
Code:
switch (player_attributes.race)
{
case 1:
player_attributes.health_stat = 1;
int& player_attributes.health_stat_reference =player_attributes.health_stat;
cout << "You reach up with a hoof and touch the shattered remnants of your horn.\n Instantly, a fire shoots through your skull and you writhe in pain. \nThe mare yanks your hoof away. \n \"Don't touch that!\" \n She grabs your head and looks you dead in the eye. \n\"Look, I caulked it in time, There's a chance it will heal, \n but if you poke at it, or try to throw\naround magic, that's going to be a lot less likely.\" \n\n";
break;
case 2:
player_attributes.health_stat = 1;
int& player_attributes.health_stat_reference =player_attributes.health_stat;
cout << cout << "You try to spread your wings and cry out in pain, noticing the bandages too \n late. you feel like there are a thousand firey daggers rammed into your wings, \nor what's left of them.you huddled yourself into a ball. \n The mare reaches out a hoof and turns your head to face her. There's a strange determination in her eyes. \"Listen to me. You, are going to fly again, you \njust need to be patient\" She looks away wistfully for a moment. You feel \nstrangely awkward. \n\n";
break;
case 3:
player_attributes.health_stat = 1;
int& player_attributes.health_stat_reference =player_attributes.health_stat;
cout << "You shift the blanket away and scream at the top of your lungs. Your left hind leg now ends right below your hock in a carefully woven wad of bandages. Old gods... You were a soldier! Even if the General didn't banish you for the desertion how are you going to feed Mom? How could you work? How could you- The mare puts a hoof on your shoulder and looks you dead in the eye. \n\"Listen to me okay? If I have anything to say about it, you are going to WALK out of here. We don't care which side you were fighting on.\" \n\n";
break;
}
In this case switch, I get a compiler error every for every line where I try to define a reference that says:
error: expected initializer before '.' token
None of my internet searches so far have been able to turn up why.
Furthermore, I have another compiler error when I try to access the array "name" within the structure above using the cin.getline function, which I attempted to do as follows:
Code:
cout<<"Please enter your character's name (255 characters or less): ";
cin.getline (player_attributes.name, 256);
Despite the fact that I used basically the same syntax to get input to the string defining the character's name in another program, and that I've inserted header data such that:
Code:
#include <iostream>
using namespace std;
I get a compiler error stating that:
error: no matching function for call to 'std::basic_istream<char, std::char_traits<char> >::getline(int [256], int)'
I really have no idea what's going on here, despite my research. Does anyone have any ideas as to what would be causing these things? I would be extremely grateful for any help that could be offered.