-
having trouble them them!! :mad:
this program has no purpose except to teach me about classes (incase you're wondering :D)
CPlayer Class
Code:
// Player.cpp: implementation of the CPlayer class.
//
//////////////////////////////////////////////////////////////////////
#include "iostream.h"
#include "Player.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CPlayer::CPlayer()
{
}
CPlayer::~CPlayer()
{
}
void CPlayer::jump()
{
cout << "Player jumped!";
}
Now here is the main part of my code.
Code:
#include <iostream>
using namespace std;
void main()
{
CPlayer guy;
guy.jump(); // The guy suppose to JUMP here but he doesn't!!!
}
for some reason this ain't working so could someone spot a mistake in here :confused:
-
I don't spot anything unusual immediately. However without your class declaration I can't be sure. I noticed in your main that you have
#include <iostream>
using namespace std;
but in your CPlayer class you have:
#include "iostream.h"
Why?
iostream (without the .h) isn't needed unless you plan on using stl in your project. Either way you should use one or the other.
Using this main
Code:
#include <iostream>
#include "Player.h"
using namespace std;
void main()
{
CPlayer guy;
guy.jump(); // The guy suppose to JUMP here but he doesn't!!!
}
This Header:
Code:
class CPlayer{
public:
CPlayer();
~CPlayer();
void jump();
};
and This CPP:
Code:
#include "iostream.h"
#include "Player.h"
CPlayer::CPlayer()
{
}
CPlayer::~CPlayer()
{
}
void CPlayer::jump()
{
cout << "Player jumped!";
}
It works fine. I get "Player jumped!" on the screen
[Edited by CthulhuDragon on 08-24-2000 at 10:46 AM]
-
thanks
Thanks CthulhuDragon!! i fogot to include the "player.h" in my main file, so now it works like a charm! :p.
the reason I used <iostream> is because someone said you can use this too. it works fine both ways now so thanks again!!
-
I beg to differ on the iostream issue. It isn't part of the STL, but of the Standard C++ Library, which includes the IOStream library, string streams, and STL. I always use the std:: headers, since they are actually better than Microsoft's own one. (Actually, MS hint that you should use the std:: ones).