Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio: FeinWindows - replacement windows manager for Visual Studio, and more...
If the code is too long to post then my suggestion would be to compile it and post all of the error messages. You originally only posted what you called errors 2-4. What was error 1? You may have decided that it wasn't relevant but you should not do that. Most of the experts on this board understand error messages and can determine the most likely causes.
In addition to posting all of the error messages you should post the code where the first error occurs. We can start with error #1 and go from there.
Last edited by 0xC0000005; March 28th, 2007 at 09:40 AM.
I'm not 100% sure about this because I've never seen it, but your player class does not have a constructor! (This could be your problem.)
Normally you'll have in the header:
Code:
player class.h:
class player{
public:
player();~player();
float size; //the size of the player
float x;
float y;
float z;
int score;
int lives;
float time;
};
Along with that, you would have an implementation (or it could be included in the header if needed.
Code:
class player{
public:
player(){ };~player(){ };
...
I suspect that the error really occurred on the line preceding the one you point to, which would indicate it could not create an object of the player class.
Hope that helps.
The compiler will automatically generate a constructor, copy constructor and assignment operator if you do not provide one. However, if you do provide a constructor that takes any number of parameters, you must also provide a default ctor (the compiler will not auto generate one for you).
i tried to upload the zipped folder but it was 4mb after being zipped, and too big to upload. in the compilation, there are alot of warnings about various things, such as truncating a double to a float etc. and the first 'error' is a warning.
this warning is:
_______________________________________
Warning 1 warning C4305: 'initializing' : truncation from 'double' to 'float' y:\0501334\my documents\2nd year\graphics programming\new folder\myproj\main.cpp 28
_______________________________________
and all the errors are:
_______________________________________
Error 2 error C2143: syntax error : missing ';' before '.' y:\0501334\my documents\2nd year\graphics programming\new folder\myproj\main.cpp 37
____
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int y:\0501334\my documents\2nd year\graphics programming\new folder\myproj\main.cpp 37
____
Error 4 error C2371: 'me' : redefinition; different basic types y:\0501334\my documents\2nd year\graphics programming\new folder\myproj\main.cpp 37
____
Error 5 error C2143: syntax error : missing ';' before '.' y:\0501334\my documents\2nd year\graphics programming\new folder\myproj\main.cpp 38
____
Error 6 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int y:\0501334\my documents\2nd year\graphics programming\new folder\myproj\main.cpp 38
____
Error 7 error C2371: 'me' : redefinition; different basic types y:\0501334\my documents\2nd year\graphics programming\new folder\myproj\main.cpp 38
_____________________________________________
after that there are just warnings about my shady coding
This is VERY IMPORTANT: As Hobson and VladimirF have already suggested, you must locate the other variable named 'me' that is conflicting with the one of type 'player' that you have shown in your post.
I can generate the same errors you show with this code:
Code:
int me;
player me;
me.size=2;
me.y=5;
You can delete the Debug and/or Release folders in your project (the ones that contain object and executable files) before zipping it. I really doubt that you have 4MB of compressed source code.
And another thought: is the code that you show defined outside of a function?
Code:
#include "player.h"
player me;
me.size=2; //line 37 here
me.y=5; //line 38
void SomeFunction()
{
}
If so, that could account for your at least part of the problem.
Last edited by 0xC0000005; March 29th, 2007 at 04:37 AM.
i already tried changing 'me' to other variable names, but the same error occured. i also searched the code for any text " me" (with the space) and found no other variable called 'me'.
i have just taken the actault code, instead of thewhole project (thats why it was so big), and zipped it, and attached it to this post.
I was adding to my post the part about making sure that the code causing the errors was not outside of a function and now I see that my suspicion was correct.
It is OK to declare 'player me' outside of a function but initialization of its parameters must be done inside of a function. try moving the two lines that set size and y inside of WinMain().
Better yet, start learning the concept of working with classes by adding an appropriate constructor that takes arguments for size and y:
Code:
class player{
public:
float size; //the size of the player
float x;
float y;
float z;
int score;
int lives;
float time;
player(float size, float y)
: size(size), y(y)
{
}
};
// Now you can declare your player like this:
player me(2,5);
My example of adding a constructor is very crude. You should really set all variables to an initialized state even if they aren't included in the parameter list:
thanks very much! it compiles and runs now! (unfortunatly i still have alot of work to do on it ) didnt realise that you wre unable to initialise class parameters outside of functions, cheers to everyone who gave this a look!
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.