Sign in to follow this  
_Sauce_

Yes... More compile errors...

Recommended Posts

I'm getting a very strange (to me at least) error when compiling my project in these 3 lines where I declare an object of class InitGameData called Init:
InitGameData Init;
void Init.SetScreenResX(800);
void Init.SetScreenResY(600);

I get 6 errors, 3 per line, here is the Compile Log:
------ Build started: Project: BiggerFish, Configuration: Release Win32 ------
Compiling...
BiggerFish.cpp
.\BiggerFish.cpp(23) : error C2143: syntax error : missing ';' before '.'
.\BiggerFish.cpp(23) : error C2182: 'Init' : illegal use of type 'void'
.\BiggerFish.cpp(23) : error C2371: 'Init' : redefinition; different basic types
        .\BiggerFish.cpp(22) : see declaration of 'Init'
.\BiggerFish.cpp(24) : error C2143: syntax error : missing ';' before '.'
.\BiggerFish.cpp(24) : error C2182: 'Init' : illegal use of type 'void'
.\BiggerFish.cpp(24) : error C2371: 'Init' : redefinition; different basic types
        .\BiggerFish.cpp(22) : see declaration of 'Init'
.\BiggerFish.cpp(227) : warning C4996: 'strcpy' was declared deprecated
        C:\Program Files\Microsoft Visual Studio 8\VC\include\string.h(73) : see declaration of 'strcpy'
        Message: 'This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
.\BiggerFish.cpp(234) : warning C4996: 'strcpy' was declared deprecated
        C:\Program Files\Microsoft Visual Studio 8\VC\include\string.h(73) : see declaration of 'strcpy'
        Message: 'This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
.\BiggerFish.cpp(241) : warning C4996: 'strcpy' was declared deprecated
        C:\Program Files\Microsoft Visual Studio 8\VC\include\string.h(73) : see declaration of 'strcpy'
        Message: 'This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
.\BiggerFish.cpp(289) : warning C4996: 'strcpy' was declared deprecated
        C:\Program Files\Microsoft Visual Studio 8\VC\include\string.h(73) : see declaration of 'strcpy'
        Message: 'This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
Build log was saved at "file://c:\Documents and Settings\Hillam\My Documents\Visual Studio 2005\Projects\BiggerFish\BiggerFish\Release\BuildLog.htm"
BiggerFish - 6 error(s), 4 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
And the sourcecode for my class:
//////////////////////////////////////////////////////
// InitGameData.h
//////////////////////////////////////////////////////

#pragma once

class InitGameData
	{
	private:
		unsigned int i_ScreenResX;
		unsigned int i_ScreenResY;

	public:
		InitGameData(void);
		~InitGameData(void);

		void SetScreenResX(int ScreenResX);
		int GetScreenResX();
		void SetScreenResY(int ScreenResY);
		int GetScreenResY();
	};

And it's Declarations:
//////////////////////////////////////////////////////
// InitGameData.cpp
//////////////////////////////////////////////////////

#include "InitGameData.h"
#include "Fish.h"

//////////////////////////////////////////////////////
// InitGameData()
//////////////////////////////////////////////////////
InitGameData::InitGameData(void)
{
	Fish Player1;
	Player1.SetLevel(0);
	Player1.SetExp(0);
	Player1.SetMoveSpeed(5);
	Player1.SetMoveDirection("Left");
	Player1.SetLocationX(GetScreenResX() / 2);
	Player1.SetLocationY(GetScreenResY() / 2);

	Fish NPC1;
	NPC1.SetLevel(2);
	NPC1.SetExp(5);
	NPC1.SetMoveSpeed(5);
	NPC1.SetMoveDirection("Right");
	NPC1.SetLocationX(600);
	NPC1.SetLocationY(250);
}

//////////////////////////////////////////////////////
// ~InitGameData()
//////////////////////////////////////////////////////
InitGameData::~InitGameData(void)
{
}

//////////////////////////////////////////////////////
// SetScreenResX()
//////////////////////////////////////////////////////
void InitGameData::SetScreenResX(int ScreenResX)
{
	i_ScreenResX = ScreenResX;
}

//////////////////////////////////////////////////////
// GetScreenResX()
//////////////////////////////////////////////////////
int InitGameData::GetScreenResX(void)
{
	return i_ScreenResX;
}

//////////////////////////////////////////////////////
// SetScreenResY()
//////////////////////////////////////////////////////
void InitGameData::SetScreenResY(int ScreenResY)
{
	i_ScreenResY = ScreenResY;
}

//////////////////////////////////////////////////////
// GetScreenResY()
//////////////////////////////////////////////////////
int InitGameData::GetScreenResY(void)
{
	return i_ScreenResY;
}

Any ideas? I am really sick of getting erros that seem to have nothing to do with what it says it is. Why on earth would I want to put a semicolon in front of a period? I checked the help files for these errors but that didn't seem to help...

Share this post


Link to post
Share on other sites
When you use your class instance you do not need void. The code should look like this


InitGameData Init;
Init.SetScreenResX(800); // No void on this line
Init.SetScreenResY(600); // No void on this line

Share this post


Link to post
Share on other sites
Unless you have a variable of type void you want to return the value to. LOL I've never tried anything like that, I should try it and see what happens. lol

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
You can't declare one.


void is an incomplete object. You can pass pointers around of type void*, but not a void itself.

Share this post


Link to post
Share on other sites
i see a picture in my head of a void vs. an int. the void walks up to the int. the int is like: WHATTTT BUT YOU CAN'T BE DECLARED!!!! and the void is like: HA! I am a pointer!!! the int is like: oh noo!! not a pointer!!! aaahhh!!! he runs away and the void pointer chases after him. lol i can write a whole story on this.

Share this post


Link to post
Share on other sites
A couple of minor changes to the story... instead of the void saying "I am a pointer"...

int: WHAT?!? BUT YOU CAN'T BE DECLARED!!!! IMPOSSIBLE!

void: (Raises its arm and extends a single bony and decaying finger from beneath its tattered black robes to within an inch of the int's nose)

int: NO! (scrambles backwards, losing his balance, without letting his horrified gaze leave the void) God help me, a pointer!

(Cut to a scene of frightened villagers halting, as they go about their business in the dark of night, to the horrific sounds of distant, blood-curdling screams)

Share this post


Link to post
Share on other sites
LOLLL I seriously might consider making a game that is like this. You have a number of characters Int/Void, etc to choose one (if a fighting, and the different characters can fight each other). I don't know, it might be like an RPG type game, you are a Void Pointer, and you begin you journey with nothing but a Null Pointer, which is going to be his weapon, which is really dull. Later as he advances through the game, his gets upgrades for his Pointer. Then he gets to Datatype Palace, where he has a choice of all kinds of datatypes. He becomes a strong warrior eventually, and encounters many enemies. A String goes "I shall use my erase() function and you will be all gone" and the Void Pointer replies "I need to be pointing to a string for your functions to have any effect on me, behold I am a VOID POINTER!!!" The String gets all scared and surrenders, and the Void Pointer "voids" the string, and obtains his power or something. He eventually gets to a Float, and the Void Pointer goes "Let's see if you are as wimpy as your brothers Int or Double" The float goes "I am the oldest, or am I..." They fight, the float of course loses. Then the final boss can be like a Destructor or like a Void Pointer pointing to a Void Pointer, pointing back to the original Void Pointer and they are like super-difficult to defeat. LOL, Void Pointer arrives at Volatile Valley, and uses an if-else to jump over the whole thing and get past the valley. Eventually in the end the Void Pointer encounters his worst fear... a NULL. Now NULL is chasing Void Pointer as he yells: AAAHHH A NULL!!!! NOT A NULLL!!!! NULL comes to a stop and goes: "Aww, don't be scared, I am just a NULL pointer!" as he takes off his disguise and reveals that he is only a pointer also or something like that.

Share this post


Link to post
Share on other sites
The huge plot twist at the end of the game is when you find out that you point to the same thing as the evil void pointer.

Ok, we should stop now... you know... before we get silly.

Share this post


Link to post
Share on other sites
Quote:

You can pass pointers around of type void*, but not a void itself.


...which is what I said. You can't declare instance of type void. void* is an entirely different type, and thus another matter altogether.

Share this post


Link to post
Share on other sites
sorry, removing the void from each line didn't help, I still get the same errors, i think removing the void was the first thing I ever tried... Oh, and yoou HAVE to make a game like that it would be so awesome... and educational! C++ n00bs could play and harden their knowledge of pointers, types, etc. It would be so great!

Share this post


Link to post
Share on other sites
- Functions taking no parameters should be declared ReturnType Function();
- You need not declare a destructor in this particular case - the default destructor the compiler generates for you is enough.
- You may want to use an initializer list in your constructor definition, for efficiency. It's also a good habit to get into in general, since some members can only be initialized there.
- Your constructor creates Fish temporaries that are destroyed when your constructor exits. These should presumably be global or part of a GameData class (which might be passed to InitGameData's constructor.
- Or, a GameData class should simply init these members via its constructor.

Make the appropriate changes, then post back if you have any more questions.

Share this post


Link to post
Share on other sites
Why on earth did I make an entire class to deal with initialising everything?!? It's not like I'm going to need to initialise it twice in two seperate classes?!? Would I just create a function in my main source file to initialise that stuff? Dammit I need to start thinking straight before I start typing.

Share this post


Link to post
Share on other sites
I find it helps me to use a pen and paper and outline my design before I touch my keyboard.

edit:

Quote:
Would I just create a function in my main source file to initialise that stuff?

If you want initialization to occur in GameData's constructor, all you need to do is create a GameData object, whether that be a global itself, or as a member in another class.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this