giving an array of PALETTEENTRY's as a parameter to a function.


I have a problem with a function I wrote. It should fill an array of PALETTEENTRY’s with random colors. But I get an error.

This is the crucial part of main.cpp :

///////////////////////////////////////////////////////////////////////////

#define WIN32_LEAN_AND_MEAN

#include <windows.h>  
#include <windowsx.h>  
#include <stdio.h>
#include <ddraw.h>
#include <stdlib.h>
#include <time.h>

#include "functies.h"

PALETTEENTRY palette[256]; // palette storage

int maakRandomPalette(palette);

//////////////////////////////////////////////////////////////////////////////

This is functies.cpp :

/////////////////////////////////////////////////////////////////////////////

#define WIN32_LEAN_AND_MEAN  

#include <windows.h>   // include alle windows headers
#include <windowsx.h>  // include bruikbare macro's
#include <stdio.h>
#include <ddraw.h>
#include <stdlib.h>
#include <time.h>
#include <io.h>

#include "functies.h"

int maakRandomPalette(PALETTEENTRY palette[])
{
      srand(time(0));
      // build up the palette data array
      for (int color=1; color < 255; color++)
      {
            // fill with random RGB values
            palette[color].peRed   = rand()%256;
            palette[color].peGreen = rand()%256;
            palette[color].peBlue  = rand()%256;
            // set flags field to PC_NOCOLLAPSE
            palette[color].peFlags = PC_NOCOLLAPSE;
    } // end for color

      // now fill in entry 0 and 255 with black and white
      palette[0].peRed   = 0;
      palette[0].peGreen = 0;
      palette[0].peBlue  = 0;
      palette[0].peFlags = PC_NOCOLLAPSE;

      palette[255].peRed   = 255;
      palette[255].peGreen = 255;
      palette[255].peBlue  = 255;
      palette[255].peFlags = PC_NOCOLLAPSE;
return(1);
}

//////////////////////////////////////////////////////////////////////////////

And here functies.h :

//////////////////////////////////////////////////////////////////////////

int maakRandomPalette(PALETTEENTRY palette[]);

////////////////////////////////////////////////////////////////////////////

And I get this error :

////////////////////////////////////////////////////////////////////////

--------------------Configuration: bitmaps - Win32 Debug--------------------
Compiling...
main.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\bitmaps\main.cpp(58) : error C2440: 'initializing' : cannot convert from 'struct tagPALETTEENTRY [256]' to 'int'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Skipping... (no relevant changes detected)
functies.cpp
Error executing cl.exe.

bitmaps.exe - 1 error(s), 0 warning(s)

////////////////////////////////////////////////////////////////////////////////////////

I have visual c++ enterprise edition and windows 2000.

Does anyone know how to solve this error ???????

Thanks in advance !!!!
bockskeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlexFMCommented:
Where is line 58?

I would write this function by such way:

int maakRandomPalette(PALETTEENTRY* palette)
{
    ...
}

I don't think that compiler has problems with maak instead of make :-)
0
bockskeAuthor Commented:
With the pointer, I still get the same error, nothing changes.

Line 58 is the line where I call the function in main.cpp.

Oh, and the "maak", that's dutch, I'm from Belgium :-)
0
bockskeAuthor Commented:
I just found the error!

I placed an int before my call to the function, that was the problem, It now compiles !

So thanks anyway for the help, AlexFM
0
AxterCommented:
Your forward declaration is different from your function implementation.

int maakRandomPalette(palette);

palette is not a type.
Change your forward declaration to match your actual function arguments.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bockskeAuthor Commented:
I just said, that line is not a declaration, but a call to the function, so I removed the int.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.