Thread: Passing pointer...reference...

  1. #1
    Ecologist
    Join Date
    Aug 2001
    Location
    Utah.
    Posts
    1,291

    Passing pointer...reference...

    First, here is the related code:

    Code:
    //Palette class.
    class PALETTE{
      public:  
        unsigned char red[256];
        unsigned char green[256];
        unsinged char blue[256];
    };
    //inside Bitmap class. Stores palette in passed palette class.
    void cBITMAP::ExtractPaletteAndStore(const PALETTE &palette);
    
    //inside graphics.h
    void SetPalette{const PALETTE *palette);
    This is what I want to do: Okay, the functions
    work fine if I declare a PALETTE variable. But,
    I want the palette to be on the freestore. I
    want to be able to pass the PALETTE pointer
    through the ExtractPaletteAndStore function.

    Code:
    //works.
    PALETTE L1Palette;
    L1Image->ExtractPaletteAndStore(L1Palette);
    SetPalette{&palette);
    
    //doesn't work, but this is what I want to do.
    PALETTE *L1Palette = new PALETTE;
    L1Image->ExtractPaletteAndStore(L1Palette);
    SetPalette{L1Palette);
    I want to be able to store the palette in the
    allocated memory. How would I go about doing this?
    Can I do this without chaning the function
    prototypes?

    DJGPP. Windows95. 13h Game.

    Thanks a lot,
    -ethic
    Staying away from General.

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    Code:
    PALETTE *L1Palette = new PALETTE;
    L1Image->ExtractPaletteAndStore(*L1Palette);
    SetPalette{L1Palette);
    ya know? gotta dereference the pointer first!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Newbie question about pointers in function parameters.
    By sojurn in forum C++ Programming
    Replies: 14
    Last Post: 01-20-2007, 09:21 PM
  4. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  5. How to: Use OpenGL with Jgrasp
    By Pickels in forum Game Programming
    Replies: 3
    Last Post: 08-30-2005, 10:37 AM