# Totally Weird Error(C++)

This topic is 4416 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

#include "iostream" #include "cstdlib" #include "ctime" #include "class basePlayer.h" using namespace std; int main() { time_t t; srand((unsigned) time(&t)); return 0; } ////////////////////////////////////////////////////////////////////// //class basePlayer.h file #ifndef basePlayer #define basePlayer #include <vector> #include <string> using namespace std; class basePlayer { public: //Constructors basePlayer();//error C2059: syntax error : ')' error C2238: unexpected token(s) preceding ';' //Pointers basePlayer* enemy;//error C2501: 'enemy' : missing storage-class or type specifiers //Stats int HP, MP, Strength, Defence, Luck, Speed, totalExperience, experience, Level;//Basic stats string Name; };//error C2639: compiler generated default constructor required by unnamed class This is compiled with MVC 6.0. I posted the errors next to the lines, and they make no sense. All the code is correct... right?

##### Share on other sites
Why have you got:

#include "class baseplayer.h"

take out the class and the space and recompile.

Dave

##### Share on other sites
Looks fine to me. Sounds like another famout MSVC 6 problem. I'd highly recommed upgrading to VS2005 if possible. The express version is even free.

Have you tried doing Build -> Clean, and recompiling?

##### Share on other sites
Quote:
 Original post by DaveWhy have you got:#include "class baseplayer.h"take out the class and the space and recompile.Dave

Thats the name of his file. Its non conventional, but he will still have to rename the header file too if that is the problem.

##### Share on other sites
you have a define for basePlayer.

##### Share on other sites
Usually the defines are the name of the header file:

#ifndef _basePlayer_h_
#define _basePlayer_h_

#endif <---- is this included at the end in your code?

Also, is there a body for the constructor somewhere?

//Constructors
basePlayer() { }

##### Share on other sites
all these #ifndef .. #define .. #endif constructions are very popular, i know; but insted of doing this, you can do also...
#pragma once

##### Share on other sites
Quote:
 Original post by Alex Bakerall these #ifndef .. #define .. #endif constructions are very popular, i know; but insted of doing this, you can do also...#pragma once...in your headerfiles.

Or you could use a method that will work under any standards compliant compiler, the usual include guards...

##### Share on other sites
Quote:
 Original post by Alex Bakerall these #ifndef .. #define .. #endif constructions are very popular, i know; but insted of doing this, you can do also...#pragma once...in your headerfiles.

That only works for MSVC. If you want your code to compile with other compilers, you should use the normal include guards.

##### Share on other sites
As was mentioned before, you #define basePlayer and then try to use the same name for your class. Basically what is happening is this (at least I'm fairly certain):

1.) You define an empty constant named basePlayer. #define instructs the compiler to replace any instance of the name you defined with the value you specify after it. In this case, you're instructing the preprocessor (runs before the compiler) to replace every instance of the name "basePlayer" with "" (nothing).

2.) You try to name a class basePlayer. The preprocessor sees this string and replaces it with any empty string.

3.) When you try to declare the constructor, the compiler actually sees this:
public: ();
and properly notifies you that this makes no sense.

4.) At the pointer declaration, the compiler sees this:
* enemy;
and properly notifies you that there is no "storage-class or type specifier" preceding the name enemy, which it requires.

5.) And finally, the real clue to your problem is the last error, where it's complaining about the unnamed class. Again, it's because you've instructed the preprocessor to treat that name as an empty string.

Compiler error messages can often be very cryptic and misleading, but in this case it turns out they were pretty much straight to the point.

As was also mentioned above, and as is advisable any time you're #defining things in the preprocessor, you should use names that won't appear elsewhere in your code. Often people use all capital letters for such things. The common standard for preventing multiple header inclusion is:

#ifdef MYCLASSNAME_H
#define MYCLASSNAME_H

#endif

• 10
• 19
• 14
• 19
• 15