#19829 - CodeMasterMike - Mon Apr 26, 2004 1:30 pm
hi!
I'm sitting here and trying to have a struct pointer as a inparameter to a class function. here is the struct:
typedef struct tagSprite
{
unsigned short attribute0;
unsigned short attribute1;
unsigned short attribute2;
unsigned short attribute3;
}Sprite,*pSprite;
Then I declare the pointer in the main file:
pSprite pSprites[255];
and then I'm going to send it into the function something like this:
object->function(&pSprite)
the problem is when I try to start the program, I'll get an error that I can not understand
I get the error in the header for the class which is suppoes to take the pointer as a inparameter:
function(pSprite pSprites)
The error is:
error: type specifier omitted for parameter `pSprite'
Can someone help me with this problem??
Everything is made in C++ code
#19830 - sgeos - Mon Apr 26, 2004 2:05 pm
This is an array:
pSprite pSprites[255];
I think you want either:
object->function(pSprites)
OR
object->function(&pSprites[0])
At least that is how I would do things in C.
-Brendan
#19831 - CodeMasterMike - Mon Apr 26, 2004 2:09 pm
yeah, I have done like this:
object->function(&pSprites[255])
But it is in the header of the class that the function is in, where the problem lies(I think, but the errorcode shows me that, when it gives me the error code)
Is the name type of the pointer ( pSprite ) that gives the error.
It looks like it doesn't see the ' pSprite ' as the type for the pointer.....
#19833 - NoMis - Mon Apr 26, 2004 2:20 pm
You have to make sure that the function recognises pSprite as a type. It has to be declared befor you declare the function either in an included headerfile or in the file itself.
Code: |
typedef struct tagSprite
{
unsigned short attribute0;
unsigned short attribute1;
unsigned short attribute2;
unsigned short attribute3;
}Sprite,*pSprite;
....
class CExample
{
void foo(pSprite pSprites);
...
};
|
NoMis
#19835 - CodeMasterMike - Mon Apr 26, 2004 2:31 pm
I have first the struct in a header file.
then I include it first in the main cpp file, and then in the other class cpp file, so it should not be any problem.
If I run the code that's in the function directly in the main file, it works fine. But I must have it in another function class.
#19844 - sajiimori - Mon Apr 26, 2004 6:15 pm
Since it hasn't been solved after a couple replies, I think that warrants posting a full program. Remove all the unrelated code and post a minimal program that has the problem.
As for my 2 cents, I wouldn't make seperate typedefs for pointers at all. My first C book did that, and I thought there must have been a good reason for it. As it turns out, there wasn't.
#19850 - poslundc - Mon Apr 26, 2004 7:07 pm
CodeMasterMike wrote: |
yeah, I have done like this:
object->function(&pSprites[255]) |
You would want it to be &pSprites[0], or just pSprites. &pSprites[255] gives you a pointer to the end of the array, not the beginning.
HTH,
Dan.
#19852 - CodeMasterMike - Mon Apr 26, 2004 9:56 pm
Thanks for your efforts guys!
But I tried another way, mayby not the best sollution to it. But anyway.
What I did was that I moved the declaration into the class that would have it as a inparameter and made it global.
And so far, it works.
It is a strange problem, for I doesn't understand what the type is, even though it is declared and the header was included..
I tested it in Visual studio 2003, and it worked without problems there...