A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

What is wrong -_-...?

1.9k views · started by HTML ·
#1
What is wrong -_-...?
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
#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
#include <iostream>
using namespace std;

class Player
{
public:


Player();
void Skeletonattack();
void Skeletonxp();
void Skeletonlvl();

private:
int health; int experience; int level;
};



solider.cpp
#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
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
#2
When i get home ill see what i can do. Im at robotics meeting right now. (Nice coincidence. Program the robot in C++ >.<;)

but yea. Ill see what i can do to fix these errors for you.
#3
So my internet just failed me and erased everything I had written... so quick answer:

- Get rid of soldier.cpp, dump everything you have there to soldier.h

Didn't test it, but it should be a quick fix to your problem. Also add a destructor to your Player class. Search for C++ compiling with Multi-header files, Classes, and Scopes in Google or something, that will set you in the right track for OOP in C++.
#4
Riddle wrote:
So my internet just failed me and erased everything I had written... so quick answer:

- Get rid of soldier.cpp, dump everything you have there to soldier.h

Didn't test it, but it should be a quick fix to your problem. Also add a destructor to your Player class. Search for C++ compiling with Multi-header files, Classes, and Scopes in Google or something, that will set you in the right track for OOP in C++.



It will defeat the purpose if I do that. I need to have all three files. I'll check out google for sure though. I'll also re-read this section on OOP again. -_-;