Well first off, this is my very first post on the forums. So hi! :D
I've been learning C++ for a while now, finding internet tutorials, reading books, consulting my uncle once but that was only while he was visiting a month ago. I ran into problems, and usually found the answer via google or my "Sam's Teach Yourself C++" book by Jesse Liberty and Rogers Cadenhead. Don't mean to advertise, but if other beginners want to take a look at that then I highly reccomend it.
So to get to the point here, I can't find the answer this time. I've found related questions, but none have seemed to help me (they probably could, I just get lost very easily in all the other answers and then I don't find mine).
My problem is that I can't figure out what is wrong with how I'm declaring/linking my
class.cpp,
header.h, and
main.cpp.
I've been coding some things like rectangle calculators, guessing games, and so on, and I finally decided I (aka
thought I) was ready to make a text-based game. I have some done already, but I never really bothered to separate out the classes from the main. I was trying to tonight, and after about three hours of working it over (including numerous breaks) I still get the same error (and the same headache):
|
error: expected unqualified-id before 'public'
|
I can't seem to get rid of this one error, no matter how I work it.
Here's the code:
zombie.h
1 2 3 4 5 6
|
public class zombie()
{
int hp;
int st;
int ref;
};
|
zombie.cpp
1 2 3 4 5 6 7 8
|
#include "zombie.h"
void zombie()
{
int hp = (rand()%2)+5;
int st = (rand()%2)+5;
int ref = (rand()%2)+5;
}
|
And here's the "#include"s of
main.ccp, where I'm trying to call up a zombie...
main.cpp
1 2 3 4 5 6
|
#include <iostream>
#include <time.h>
#include <cstdlib>
using namespace std;
#include "zombie.h"
|
In
main.cpp, all the code worked before I even implemented the zombie files. Now, I put in the
zombie.h and
zombie.cpp, and added
cout << zombie.st;
to
main.cpp and it breaks everything with that one little error.
Anyone who actually knows what they're doing have any advice? Thanks.