Yes... More compile errors...

Started by
13 comments, last by yaustar 17 years, 11 months ago
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...
Advertisement
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 lineInit.SetScreenResY(600); // No void on this line
Matt
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
You can't declare one.
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.
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.
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)

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.
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.
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.

This topic is closed to new replies.

Advertisement