I'm teaching myself how to use classes in C++, and I run into a issue when I do:
cout << One.Player::inventory(slotOne);
I'm not sure why, but it tells me:
error "slotOne" was not declared in this scope.
When I compile. I'm using Code::Blocks, and using the GNU/GCC compiler on Windows 10 version 1709, build 12699.192, and have never had this sort of issue before. What have I done wrong, and how can I fix it?
#include <iostream>
#include <ctime>
#include <stdlib.h>
#include <algorithm>
using namespace std;
std::string longsword = "Longsword: 1d8 slashing";
std::string shortsword = "Shortsword: 1d6 slashing";
std::string dagger = "Dagger: 1d4 slashing";
std::string falchion = "Falchion: 1d10 slashing";
std::string longbow = "Longbow: 1d8 piercing \t Range: 110/330 yards";
class Player {
public:
std::string inventory();
int health();
int hunger();
int exhaustion();
};
int main() {
srand(time(NULL));
string playername;
Player One;
cout << "Welcome to -WIP-." << endl;
cout << "What is your name? \n";
cin >> playername;
cout << One.Player::inventory(slotOne);
return 0;
}
int Player::health()
{
int hp = 10;
cout << "Current health is: " << hp << endl;
return 0;
}
std::string Player::inventory() {
std::string slotOne = longsword;
std::string slotTwo = longbow;
return 0;
}