Thread: Class Name "monster" not allowed??

  1. #1
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310

    Class Name "monster" not allowed??

    I found this rather weird:

    Code:
    class monster
    {
    public:
    	int hp,maxhp,attack,defense,exp,level;//stats
    };
    monster monsters;
    The above code returned these errors:
    "E:\Tarasque\Archi\Main.cpp(55) : error C2146: syntax error : missing ';' before identifier 'monsters'
    E:\Tarasque\Archi\Main.cpp(55) : error C2501: 'monster' : missing storage-class or type specifiers
    E:\Tarasque\Archi\Main.cpp(55) : error C2040: 'monster' : 'int' differs in levels of indirection from 'struct SDL_Surface *'
    E:\Tarasque\Archi\Main.cpp(55) : fatal error C1004: unexpected end of file found
    Error executing cl.exe.

    Archi.exe - 4 error(s), 0 warning(s)"

    I found that if you change the class name from "monster" to "montr" or "monster1" (etc etc) it works...just not at "monster"...weird. Any of you have any answers?

    //napKIN
    "The best way to get answers is to just keep working the problem, recognizing when you are stalled, and directing the search pattern.....Don’t just wait for The Right Thing to strike you – try everything you think might even be in the right direction, so you can collect clues about the nature of the problem."
    -John Carmack

  2. #2
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    I compiled(MSVC) you code without any errors.
    Code:
    #include <iostream>
    using namespace std;
    
    class monster
    {
    public:
    	int hp,maxhp,attack,defense,exp,level;//stats
    };
    
    int main()
    {
    	monster monsters;
    return 0;
    }

  3. #3
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310

    hmmm....

    I was tinkering with it and couldn't get it to work...weird...I just decided to change the name to "npc"

    //napKIN
    "The best way to get answers is to just keep working the problem, recognizing when you are stalled, and directing the search pattern.....Don’t just wait for The Right Thing to strike you – try everything you think might even be in the right direction, so you can collect clues about the nature of the problem."
    -John Carmack

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Originally posted by ripper079
    I compiled(MSVC) you code without any errors.
    Idem Dito, I suggest you make more fail safe, that means
    including a constructor, specificly specifying the inheritance.
    I know this is all normally not required, but who knows your
    compiler might be nuts.

  5. #5
    Registered User dizolve's Avatar
    Join Date
    Dec 2002
    Posts
    68
    Chances are here just had a surface named monster.

    &nbsp;&nbsp;__&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;___&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;/\&nbsp;\&nbsp;&nbsp;__&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;/\_&nbsp;\&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;\_\&nbsp;\/\_\&nbsp;&nbsp;____&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_ __\//\&nbsp;\&nbsp;&nbsp;&nbsp;&nbsp;__&nbsp;&nbsp;__&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;__&nbsp;&nbsp;&nbsp;
    &nbsp;/'_`&nbsp;\/\&nbsp;\/\_&nbsp;,`\&nbsp;&nbsp;/&nbsp;__`\\&nbsp;\&nbsp;\&nbsp;&nbsp;/\&nbsp;\/\&nbsp;\&nbsp;&nbsp;/'__`\&nbsp;
    /\&nbsp;\_\&nbsp;\&nbsp;\&nbsp;\/_/&nbsp;&nbsp;/_/\&nbsp;\_\&nbsp;\\_\&nbsp;\_\&nbsp;\&nbsp;\_/&nbsp;|/\&nbsp;&nbsp;__/&nbsp;
    \&nbsp;\___,_\&nbsp;\_\/\____\&nbsp;\____//\____\\&nbsp;\___/&nbsp;\&nbsp;\____\
    &nbsp;\/__,_&nbsp;/\/_/\/____/\/___/&nbsp;\/____/&nbsp;\/__/&nbsp;&nbsp;&nbsp;\/____/
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;I&nbsp;have&nbsp;a&nbsp;BAD&nbsp;figlet& nbsp;addiction.

  6. #6
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310
    Doh! I forgot my friend was making additions to my code (we are sharing our source on an FTP), and he added an SDL_Surface named...**drum roll**...monster!!! Thanks for all the input guys.

    //napKIN
    "The best way to get answers is to just keep working the problem, recognizing when you are stalled, and directing the search pattern.....Don’t just wait for The Right Thing to strike you – try everything you think might even be in the right direction, so you can collect clues about the nature of the problem."
    -John Carmack

  7. #7
    Registered User
    Join Date
    Dec 2001
    Posts
    108
    Will this work ?

    Code:
    class monster
    {
      public:
        int hp, maxhp, attack, defense, exp, level ; //stats
    }
    monsters ;
    Last edited by DarkStar; 01-22-2003 at 10:25 PM.

  8. #8
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Originally posted by DarkStar
    Will this work ?

    Code:
    class monster
    {
      public:
        int hp, maxhp, attack, defense, exp, level ; //stats
    }
    monsters ;
    I'm not sure why you'd want to do this. Every new class you create should go in a header file whereas objects should go in functions or main. In any case, why don't you just try to compile that to find out?
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  9. #9
    Registered User
    Join Date
    Dec 2001
    Posts
    108
    Originally posted by joshdick
    I'm not sure why you'd want to do this. Every new class you create should go in a header file whereas objects should go in functions or main.
    In napkin111's case, creating a global instance may be the only alternative he has.

  10. #10
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    In an object orientated language, globals should almost never be used. It ruins the concept of modular programming (in my opinion). I do find myself making static global variabels however, when I need to do something that a file of functions can look at but I don't want the user to know about it. This has it's ups and downs obviously.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Specializing class
    By Elysia in forum C++ Programming
    Replies: 6
    Last Post: 09-28-2008, 04:30 AM
  2. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. class errors
    By romeoz in forum C++ Programming
    Replies: 3
    Last Post: 09-16-2003, 07:57 PM