This is my first attempt at making a new cpp and header file, I thought all was well before I got this funky error..can anyone help?
Practice.cpp
Code:#include "stdafx.h"
#include <iostream>
#include <string>
#include <stdlib.h>
#include "soldier.h"
using namespace std;
#define stop system("PAUSE")
#define clear system("cls")
int main ()
{
cout << "test";
stop;
return 0;
}
solider.h
Code:#include <iostream>
using namespace std;
class Player
{
public:
Player();
void Skeletonattack();
void Skeletonxp();
void Skeletonlvl();
private:
int health; int experience; int level;
};
solider.cpp
Code:#include "soldier.h"
#include "stdafx.h"
//First time with constructor..wish I had this before. >_>
//this is the dmg a skeleton takes.
void Player::Skeletonattack()
{
health - 2;
}
// The exp skeleton gives
void Player::Skeletonxp()
{
experience + 3;
}
// Testing this function
void Player::Skeletonlvl()
{
if (experience == 3)
level = 1;
cout << "You've gained a level!";
}
//First time with constructor..wish I had this before. >_>
Player::Player()
{
health = 10;
experience = 0;
level = 0;
}
Error
Code:1>------ Build started: Project: Practice, Configuration: Debug Win32 ------
1> soldier.cpp
1>c:\users\th\documents\visual studio 2010\projects\practice\practice\soldier.cpp(1): warning C4627: '#include "soldier.h"': skipped when looking for precompiled header use
1> Add directive to 'StdAfx.h' or rebuild precompiled header
1>c:\users\th\documents\visual studio 2010\projects\practice\practice\soldier.cpp(11): error C2653: 'Player' : is not a class or namespace name
1>c:\users\th\documents\visual studio 2010\projects\practice\practice\soldier.cpp(13): error C2065: 'health' : undeclared identifier
1>c:\users\th\documents\visual studio 2010\projects\practice\practice\soldier.cpp(17): error C2653: 'Player' : is not a class or namespace name
1>c:\users\th\documents\visual studio 2010\projects\practice\practice\soldier.cpp(19): error C2065: 'experience' : undeclared identifier
1>c:\users\th\documents\visual studio 2010\projects\practice\practice\soldier.cpp(24): error C2653: 'Player' : is not a class or namespace name
1>c:\users\th\documents\visual studio 2010\projects\practice\practice\soldier.cpp(26): error C2065: 'experience' : undeclared identifier
1>c:\users\th\documents\visual studio 2010\projects\practice\practice\soldier.cpp(27): error C2065: 'level' : undeclared identifier
1>c:\users\th\documents\visual studio 2010\projects\practice\practice\soldier.cpp(28): error C2065: 'cout' : undeclared identifier
1>c:\users\th\documents\visual studio 2010\projects\practice\practice\soldier.cpp(32): error C2653: 'Player' : is not a class or namespace name
1>c:\users\th\documents\visual studio 2010\projects\practice\practice\soldier.cpp(33): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\th\documents\visual studio 2010\projects\practice\practice\soldier.cpp(34): error C2065: 'health' : undeclared identifier
1>c:\users\th\documents\visual studio 2010\projects\practice\practice\soldier.cpp(35): error C2065: 'experience' : undeclared identifier
1>c:\users\th\documents\visual studio 2010\projects\practice\practice\soldier.cpp(36): error C2065: 'level' : undeclared identifier
1>c:\users\th\documents\visual studio 2010\projects\practice\practice\soldier.cpp(37): warning C4508: 'Player' : function should return a value; 'void' return type assumed