Thread: problem with class

  1. #1
    Registered User
    Join Date
    Sep 2001

    problem with class

    I made this class for a game i'm making:
    #ifndef _ENEMY_H_
    #define _ENEMY_H_
    class ENEMY{
            int currow(){return row;};
            int curcol(){return col;};
            void enemymove();   //dumb enemy
            void enemymove2(int playerrow,int playercol);  //smart enemy
            int enemytype;
            void DebugPrint();
            void Move(int rol, int col);
            void check();
            int row,col;
            int oldrow,oldcol;

    If I do something like this:
    #include "enemy.h"
    int main(){
        ENEMY enemies;  //error on this line
        //other stuff
    I get an ENEMY is not declared when I try to declare a variable of type ENEMY. whats wrong? I used other classes simular to this one, and they worked fine. I have no idea what is wrong.
    Last edited by qwertiop; 04-26-2002 at 04:30 PM.

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    why do you have an #endif? maybe your preprocessor is editing that out.
    less likely: you don't have a constructor. according to your code it exists but you don't show it.

  3. #3
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    The #endif is to close the #ifndef at the top.

    He does have a constructor:

    What he doesn't have is a destructor.

  4. #4
    whereabouts is enemy.h? it must be in the same directory if you want to use #include "enemy.h"

  5. #5
    Registered User
    Join Date
    Dec 2001
    put enemy.h in your include folder, then link to it like so:

    #include <enemy.h>

    in any program you need the engine for

  6. #6
    Registered User toaster's Avatar
    Join Date
    Apr 2002
    I think the problem is that the compiler is unable to find your enemy.h file. unless you have made a library, try using a full directory listing of the file location. use angle brackets if you made a library and use quotes if not. or you can include the directory your file exists into your compiler directory list (some compilers have this).

    oh yeah, a distructor is automatically made by the compiler if you don't make one (at least the MSVC++ compiler does).
    think only with code.
    write only with source.

  7. #7
    Registered User
    Join Date
    Sep 2001
    I had it in the same folder, it didn't work. Then I tried moving it to the include folder, and changed to angle brackets. That didn't work either. I think the compiler is able to find the file, thats not the problem. I tried compiling in both dev c++ and msvc++. I'm stumped.

  8. #8
    Registered User
    Join Date
    Apr 2002
    When I was having similar problems with header files I changed the extension to hpp and everything worked fine. Someone said .h files caused the compiler to assume it was a C file rather than c++. I don't want to start an urban legend here but if it helps.... good luck

  9. #9
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Just try putting the class in the cpp file and then compile it and see if you get the same error.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mesh Class Design problem
    By sarah22 in forum Game Programming
    Replies: 2
    Last Post: 05-20-2009, 04:52 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 09:10 AM
  4. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  5. Replies: 3
    Last Post: 12-03-2001, 01:45 PM