Seperate class files, not being declared in scope? Scroll down to the bottom to see the errors.
main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#include <iostream>
#include <string>
#include "include/Player.h"
using namespace std;
int main()
{
bool GameActive = true;
while(GameActive)
{
return 0;
}
}
|
Player.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#ifndef PLAYER_H
#define PLAYER_H
#include <string>
using namespace std;
class Player
{
public:
Player();
~Player();
string getName();
int Gold(string OP, int value);
int Level(string OP, int value);
private:
string name;
int gold = 0;
int level = 1;
};
Player User;
#endif // PLAYER_H
|
Player.cpp:
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#include "../include/Player.h"
#include <iostream>
#include <fstream>
#include <windows.h>
using namespace std;
Player::Player()
{
system("CLS");
ifstream save("RPG - SAVE.txt");
if(save.is_open())
{
User.name = getLine(save, 0);
User.gold = getLine(save, 1);
User.level = getLine(save, 2);
save.close();
cout << "Loaded your last save!" << endl;
}
else
{
cout << "Hello, you seem to be new here!" << endl;
cout << "What is your name?" << endl;
cin >> User.name;
cout << "Well, hello " << User.name << "!" << endl;
system("PAUSE");
}
}
Player::~Player()
{
ofstream save ("RPG - SAVE.txt");
if(save.is_open())
{
save << User.getName() << endl;
save << User.Gold("get") << endl;
save << User.Level("get") << endl;
save.close();
}
}
string Player::getName()
{
return User.name;
}
int Player::Gold(string OP, int value)
{
if(OP == "get" || OP == "value")
{
return User.gold;
}
else if(OP == "add")
{
User.gold += value;
}
else if(OP == "subtract" || OP == "remove")
{
User.gold -= value;
}
else if(OP == "set")
{
User.gold = value;
}
else
{
cout << "Error: GG455" << endl;
}
}
int Player::Level(string OP, int value)
{
if(OP == "get" || OP == "value")
{
return User.level;
}
else if(OP == "add")
{
User.level += value;
}
else if(OP == "subtract" || OP == "remove")
{
User.level -= value;
}
else if(OP == "set")
{
User.level = value;
}
else
{
cout << "Error: LG455" << endl;
}
}
|
When I run that, I get:
||=== RPG, Debug ===|
H:\Documents and Settings\Hank McDonald\My Documents\CodeBlocks\RPG\src\..\include\Player.h|18|warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]|
H:\Documents and Settings\Hank McDonald\My Documents\CodeBlocks\RPG\src\..\include\Player.h|19|warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]|
H:\Documents and Settings\Hank McDonald\My Documents\CodeBlocks\RPG\src\Player.cpp||In constructor 'Player::Player()':|
H:\Documents and Settings\Hank McDonald\My Documents\CodeBlocks\RPG\src\Player.cpp|14|error: 'getLine' was not declared in this scope|
H:\Documents and Settings\Hank McDonald\My Documents\CodeBlocks\RPG\src\Player.cpp||In destructor 'Player::~Player()':|
H:\Documents and Settings\Hank McDonald\My Documents\CodeBlocks\RPG\src\Player.cpp|37|error: no matching function for call to 'Player::Gold(const char [4])'|
H:\Documents and Settings\Hank McDonald\My Documents\CodeBlocks\RPG\src\Player.cpp|37|note: candidate is:|
H:\Documents and Settings\Hank McDonald\My Documents\CodeBlocks\RPG\src\..\include\Player.h|14|note: int Player::Gold(std::string, int)|
H:\Documents and Settings\Hank McDonald\My Documents\CodeBlocks\RPG\src\..\include\Player.h|14|note: candidate expects 2 arguments, 1 provided|
H:\Documents and Settings\Hank McDonald\My Documents\CodeBlocks\RPG\src\Player.cpp|38|error: no matching function for call to 'Player::Level(const char [4])'|
H:\Documents and Settings\Hank McDonald\My Documents\CodeBlocks\RPG\src\Player.cpp|38|note: candidate is:|
H:\Documents and Settings\Hank McDonald\My Documents\CodeBlocks\RPG\src\..\include\Player.h|15|note: int Player::Level(std::string, int)|
H:\Documents and Settings\Hank McDonald\My Documents\CodeBlocks\RPG\src\..\include\Player.h|15|note: candidate expects 2 arguments, 1 provided|
H:\Documents and Settings\Hank McDonald\My Documents\CodeBlocks\RPG\src\Player.cpp||In member function 'int Player::Level(std::string, int)':|
H:\Documents and Settings\Hank McDonald\My Documents\CodeBlocks\RPG\src\Player.cpp|102|warning: control reaches end of non-void function [-Wreturn-type]|
H:\Documents and Settings\Hank McDonald\My Documents\CodeBlocks\RPG\src\Player.cpp||In member function 'int Player::Gold(std::string, int)':|
H:\Documents and Settings\Hank McDonald\My Documents\CodeBlocks\RPG\src\Player.cpp|74|warning: control reaches end of non-void function [-Wreturn-type]|
||=== Build finished: 3 errors, 4 warnings (0 minutes, 3 seconds) ===|