• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

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 !!!!
0
bockske
Asked:
bockske
  • 3
2 Solutions
 
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
 
bockskeAuthor Commented:
I just said, that line is not a declaration, but a call to the function, so I removed the int.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now