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

Posted on 2004-11-11
Last Modified: 2010-04-01

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 :



#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[])
      // 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;


And here functies.h :


int maakRandomPalette(PALETTEENTRY palette[]);


And I get this error :


--------------------Configuration: bitmaps - Win32 Debug--------------------
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)
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 !!!!
Question by:bockske
    LVL 48

    Assisted Solution

    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 :-)

    Author Comment

    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 :-)

    Author Comment

    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
    LVL 30

    Accepted Solution

    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.

    Author Comment

    I just said, that line is not a declaration, but a call to the function, so I removed the int.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
    Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now