Results 1 to 4 of 4

Thread: Classes!!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    95

    Cool

    having trouble them them!!

    this program has no purpose except to teach me about classes (incase you're wondering )

    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

  2. #2
    Lively Member
    Join Date
    Jul 2000
    Posts
    94
    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]

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    95

    Wink thanks

    Thanks CthulhuDragon!! i fogot to include the "player.h" in my main file, so now it works like a charm! .
    the reason I used <iostream> is because someone said you can use this too. it works fine both ways now so thanks again!!

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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).
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width