I have wrote a program for this kind of game thing. When I go to run it, it says that a private variable declared in the class was not declared in this scope. I've wrote this program basically before and have put the code side by side but I can't see what's wrong.
Main.cpp:
#include <iostream>
#include <conio.h>
#include "Level.h"
using namespace std;
int main()
{
Level level;
level.load("2DCombatSimulatorArmy.txt");
while(true) {
level.print();
int t = getch();
}
cout << "Press any key to exit...\n";
int tmp = getch();
return 0;
}
Level.h
#ifndef LEVEL_H
#define LEVEL_H
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Level
{
public:
Level();
void Level::load(string fileName);
void Level::print();
void level::clearScreen();
private:
vector<string> _levelData;
};
#endif // LEVEL_H
Level.cpp
#include "Level.h"
#include <iostream>
#include <fstream>
#include <conio.h>
#include <cstdio>
#include <cstdlib>
using namespace std;
Level::Level()
{
//ctor
}
void Level::clearScreen() {
for(int i = 0; i < 50; i++) {
printf("\n\n\n\n\n\n\n\n\n\n");
}
}
void Level::load(string fName) {
// Loads the level into a vector
ifstream file;
file.open(fName);
if(file.fail()) {
perror(fName.c_str());
cout << "Enter any key to continue...\n";
int tmp = getch();
exit(1);
}
string line;
while(getline(file, line)) {
_levelData.push_back(line);
}
file.close();
print();
}
void Level::print() {
clearScreen();
for(int i = 0; i < _levelData.size(); i++) {
printf("%s", _levelData[i].c_str());
}
}
The problem I'm getting is that _levelData is 'not declared in the scope'. I'm not that great with C++ but I have a rough idea with it but this bug is annoying me and I can't seem to get a concrete answer.
Aucun commentaire:
Enregistrer un commentaire