Const pointer conversion.

This is a discussion on Const pointer conversion. within the C++ Programming forums, part of the General Programming Boards category; Code: void render(void) { int letterWidth=48; // the uniform width of each letter block int letterHeight=48; // the uniform height ...

  1. #1
    Samuel shiju's Avatar
    Join Date
    Dec 2003
    Posts
    41

    Const pointer conversion.

    Code:
    void render(void)
    {
    		int letterWidth=48; // the uniform width of each letter block
    		int letterHeight=48; // the uniform height of each letter block
    		int destx = 48; // the top-left X coordinate for the first letter
    		int desty = 96; // the top-left Y coordinate for the first letter
    		char *message = "HELLO WORLD";
    		// This variable will hold the pointer to the back buffer
    		IDirect3DSurface9* backbuffer = NULL;
    		// Check to make sure you have a valid Direct3D device
    		if( NULL == pd3dDevice )
    		return;
    		// Clear the back buffer to a blue color
    		pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET,
    		D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
    		// Retrieve a pointer to the back buffer
    		pd3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO, &backbuffer);
    		// Set up a counter variable to hold the letter’s position on the screen
    		int count=0;
    		// Loop through the message one character at a time
    		for ( char *c = message; c != " "; c++ )
    		{
    			// source and destination rectangles
    			RECT src;
    			RECT dest;
    			// Set the source rectangle
    			int srcY = ( ( ( *c - 'A' ) / 6 ) ) * letterHeight;
    			int srcX = ( ( ( *c - 'A' ) %7 ) * letterWidth );
    			src.top = srcY ;
    			src.left = srcX;
    			src.right = src.left + letterWidth;
    			src.bottom = src.top + letterHeight;
    			// Set the dest rectangle
    			dest.top = desty;
    			dest.left = destx + ( letterWidth * count );
    			dest.right = dest.left + letterWidth;
    			dest.bottom = dest.top + letterHeight;
    			// Increase the letter count by one
    			count++;
    			// Copy this letter to the back buffer
    			pd3dDevice->StretchRect( srcSurface, // the source surface
    			src, // the source rectangle
    			backbuffer, // the destination surface
    			dest, // destination rectangle
    			D3DTEXF_NONE); // the filter to apply
    
    		}
    		// Present the back buffer contents to the display
    		pd3dDevice->Present( NULL, NULL, NULL, NULL );
    }
    c:\documents and settings\shiju\desktop\projects\spike\loadpartbitm ap\loadpartbitmap\winmain.cpp(121) : error C2440: 'initializing' : cannot convert from 'RECT' to 'const RECT *'

    I think StretchRect expect a const pointer. Please help
    Be conservative in what you do, be liberal in what you accept from others.
    RFC 793, "Transmission Control Protocol."


  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Code:
    c:\documents and settings\shiju\desktop\projects\spike\loadpartbitm ap\loadpartbitmap\winmain.cpp(121) : error C2440: 'initializing' : cannot convert from 'RECT' to 'const RECT *'
    Pointers automatically convert to const when needed. The real problem is you aren't passing pointers in the first place.

    Code:
    			// Copy this letter to the back buffer
    			pd3dDevice->StretchRect( srcSurface, // the source surface
    			&src, // the source rectangle
    			backbuffer, // the destination surface
    			&dest, // destination rectangle
    			D3DTEXF_NONE); // the filter to apply
    Callou collei we'll code the way
    Of prime numbers and pings!

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    > for ( char *c = message; c != " "; c++ )
    This loop will never exit since you're comparing the "MESSAGE" (then "ESSAGE" and "SSAGE" string with another string with " ".
    These two pointers will never match (until one randomly catches up with the other).
    If you're really looking for the space, then
    for ( char *c = message; *c != ' '; c++ )
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  2. Another overloading "<<" problem
    By alphaoide in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2003, 10:32 AM
  3. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 11:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21