Thread: const void* problem

  1. #1
    Registered User
    Join Date
    Mar 2003

    const void* problem

    Hi there!

    I'd like to use a Comm Port object. It has a Write function, which has two variable inputs. One is a const void*, the other is an int.

    The const void* is the variable sent out via a comport, and the int is the length of the characters to send.

    My question is: How can I make a const void* from a simple AnsiString?


  2. #2
    Chief Code Coloniser!
    Join Date
    Apr 2005
    Should be a simple matter of casting. Something like this:

    char myString[200];
    string myString2;
    // do stuff
    const void* constVoidString = (const void*)myString;
    const void* constVoidString2 = (const void*)myString2.c_str();

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    You don't have to cast a pointer when assigning to a void*, only when you are going from a void* to a typed pointer

  4. #4
    Registered User
    Join Date
    Mar 2003

    I forgot about the brackets It's been awhile since I did things like this

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. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. Drawing Program
    By Max_Payne in forum C++ Programming
    Replies: 21
    Last Post: 12-21-2007, 05:34 PM
  4. Another problem with templates
    By robatino in forum C++ Programming
    Replies: 8
    Last Post: 09-21-2006, 04:32 PM
  5. problem with the const variable
    By ssharish in forum C Programming
    Replies: 2
    Last Post: 01-28-2005, 09:53 AM