|
Newbie question on c++ standard (pointer related)
I have this class (class Maptile) and a worl defined using these maptiles : Maptile *world = create_world(10,10);
The create_world() function looks like this :
As you can see I''m trying to reserve a 100 maptile classes to a maptile pointer. But obviously I''m doing something wrong. The compiler says about the line, in which the world is defined and the function called : Implict declaration of ''int create_world(...)''
Initialazation to ''Maptile *'' from ''int'' lacks a cast
Umm what int?
Thanks for any help
------------------------------If there be no heaven,may there atleast be a hell.-------------------------------Afterlife-
You'll need to declare your function before you call it.
Either by having the entire definition of the function earlier in the source-file than any calls to it, or be declaring it like this:
(This declaration must obviously also come before any calls to the function).
The usual way of doing this is to place the declarations of all your functions in a header-file, and including it in the source.
The 'int' is a legacy from way back in early C-days where everything that wasn't specified was implicitly treated as an int. Undeclared functions where regarder to return ints, undeclared variables where treated as ints, and functions that didn't have a specified return-type were assumed to return int's.
(That's why you still see some people declaring their main-functions like this:
There were a lot of weird ways of doing stuff back then, and if you look at really old C-code (K&R C) you may see something like this:
-Neophyte
- Death awaits you all with nasty, big, pointy teeth. -
Edit: Spelling-mistake.
Edited by - Neophyte on August 18, 2001 7:38:08 AM
Edit: And another one...
Edited by - Neophyte on August 18, 2001 7:39:42 AM
Edit: And yet another one...
Edited by - Neophyte on August 18, 2001 7:40:53 AM
Either by having the entire definition of the function earlier in the source-file than any calls to it, or be declaring it like this:
|
(This declaration must obviously also come before any calls to the function).
The usual way of doing this is to place the declarations of all your functions in a header-file, and including it in the source.
The 'int' is a legacy from way back in early C-days where everything that wasn't specified was implicitly treated as an int. Undeclared functions where regarder to return ints, undeclared variables where treated as ints, and functions that didn't have a specified return-type were assumed to return int's.
(That's why you still see some people declaring their main-functions like this:
|
There were a lot of weird ways of doing stuff back then, and if you look at really old C-code (K&R C) you may see something like this:
|
-Neophyte
- Death awaits you all with nasty, big, pointy teeth. -
Edit: Spelling-mistake.
Edited by - Neophyte on August 18, 2001 7:38:08 AM
Edit: And another one...
Edited by - Neophyte on August 18, 2001 7:39:42 AM
Edit: And yet another one...
Edited by - Neophyte on August 18, 2001 7:40:53 AM
Does the code calling create_world have a function prototype for it? If the calling code is in another file or above create_world in the file, you can't use the create_world identifier. An unknown function defaults to returning int, which might be the issue here. If so, you need a function prototype at the top of your file (eg. Maptile *create_world(short xsize, short ysize)) or you need to put that function above any that call it.
(EDIT: See above post for more details
)
Edited by - Kylotan on August 18, 2001 7:47:07 AM
(EDIT: See above post for more details

Edited by - Kylotan on August 18, 2001 7:47:07 AM
Maptile *create_world (xsize, ysize)
short xsize;short ysize;
{/* Body of function */}
Heh, I rember that
Anyways the function was declared... There must be something else wrong with it. Here's the whole code :
edit : hmm pretty messy without line breaks...
edit 2 : Doh, the function declaration is before the class definition. No wonder it didn't work. Thanks for bringing it to my mind
Edited by - Afterlife on August 18, 2001 8:22:19 AM
Edited by - Afterlife on August 18, 2001 8:27:18 AM
short xsize;short ysize;
{/* Body of function */}
Heh, I rember that

Anyways the function was declared... There must be something else wrong with it. Here's the whole code :
edit : hmm pretty messy without line breaks...
edit 2 : Doh, the function declaration is before the class definition. No wonder it didn't work. Thanks for bringing it to my mind

|
Edited by - Afterlife on August 18, 2001 8:22:19 AM
Edited by - Afterlife on August 18, 2001 8:27:18 AM
------------------------------If there be no heaven,may there atleast be a hell.-------------------------------Afterlife-
Just out of interest, why use the ''volatile'' qualifier on your milliseconds variable?

quote:
these must be declared volatile so the optimiser doesn't mess up
From Allegro example files. I myself don't even remember what volatile means

I find END_OF_FUNCTION(count_time); even more confusing...
Edited by - Afterlife on August 18, 2001 6:36:42 PM
------------------------------If there be no heaven,may there atleast be a hell.-------------------------------Afterlife-
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement