Hi guys, I'm just having trouble getting classes in separate files to run properly, I was just going to try out classes to set up a text-based game. so here's where I'm at;
Main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
#include <string>
#include "playr.h"
usingnamespace std;
int main ()
{
playr nm;
cout<<nm.getatk()<<" "<<nm.getdef()<<endl;
}
#ifndef PLAYR_H
#define PLAYR_H
class playr
{
public:
playr();
int getatk();
int getdef();
int gethp();
int getlvl();
private:
int atk;
int def;
int fullhp;
int lvl;
};
#endif // PLAYR_H
#include "playr.h"
#include <iostream>
#include <string>
usingnamespace std;
playr::playr()
{
int atk = 19;
int def = 18;
int fullhp = 10;
int lvl = 15;
}
int playr::getatk()
{
return atk;
}
int playr::getdef()
{
return def;
}
int playr::gethp()
{
return playr::fullhp;
}
int playr::getlvl()
{
return lvl;
}
The output I get from the cout in Main() is this;
198517466 4273152
This almost sounds like when I cout a pointer, but There are no pointers anywhere in my codes, and the numbers are even longer if I use any more of the functions from my playr.cpp file. Any clues to what's happening or what I'm doing wrong here?
I haven't tried separate files for a class before, Thank you for any help.