Hello everyone, when i realised that one single .cpp file won't work for a game, i started to make an enemy class like this :


Code:
Enemy.h

#ifndef Enemy_h
#define Enemy_h


class Enemy {
   irr::scene::IAnimatedMeshSceneNode Node;
public:
   void setNode (irr::scene::IAnimatedMeshSceneNode *node);
   irr::scene::IAnimatedMeshSceneNode getNode(void);
};

#endif

Enemy.cpp

#include "Enemy.h"

void Enemy::setNode(irr::scene::IAnimatedMeshSceneNode *node)
{
   Node = node;
}
irr::scene::IAnimatedMeshSceneNode Enemy::getNode(void)
{
   return Node;
}

Main.cpp

#include <irrlicht.h>
#include <windows.h>
#include <irrKlang.h>
#include <stdlib.h>
#include <time.h>
#include "Enemy.h"
#pragma comment(lib, "irrKlang.lib")
#pragma comment(lib, "Irrlicht.lib")
using namespace irr;
using namespace audio;


And the problem is, that enemy.h and enemy.cpp cannot use libraries, that is included in the main.cpp. So my question is, how to easily solve this problem, to avoid multiple header inclusion and so on..

And also, should i return *IAnimatedMeshSceneNode or just IAnimatedMeshSceneNode?
Mek wrote:

Code:
#ifndef Enemy_h
#define Enemy_h
If you're thinking you can't #include libraries in Enemy.cpp that are used in main.cpp, you're wrong. The whole purpose of the #ifndef #define dance is to allow exactly that. The library header files you include do the same thing, allowing them to be #included more than once; only the first inclusion has any effect.

But if somebody forgets the #ifndef #define stuff, well, double #inclusion can cause a lot of weird error messages. Fortunately, standard headers definitely don't do that.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement