Thread: Convertion from struct to 'const char'

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    16

    Convertion from struct to 'const char'

    I was just wondering whether there was a way to convert structs to chars.
    I'm trying to solve a maze using deques. I want to push the different moves onto the deque as I go along... however the compliler wouldn't let me, because it can't convert my move(which is a struct) to a 'cont char'... I'm using the push_back standard template lib fuctions.

    i'd love to know whether there's any way out of this. I didn't post the code because it's ..hmm it's a lot. I just didn't want to put anyone off....

    thanks

  2. #2
    cereal killer dP munky's Avatar
    Join Date
    Nov 2002
    Posts
    655
    you cant convert a struct to a const char

    in your struct you probably have something like this

    Code:
    struct  MyStruct
    {
         int MyInt;
         char MyChar;
    };
    if you wanted you could do something like this
    Code:
    const char MyConstChar = MyStruct.MyChar;
    otherwise i dont think there is a way to do it
    guns dont kill people, abortion clinics kill people.

  3. #3
    Registered Luser
    Join Date
    Apr 2003
    Posts
    17

    Re: Convertion from struct to 'const char'

    Originally posted by doampofo
    I'm trying to solve a maze using deques. I want to push the different moves onto the deque as I go along... however the compliler wouldn't let me, because it can't convert my move(which is a struct) to a 'cont char'... I'm using the push_back standard template lib fuctions.
    Why not use a deque<yourstruct> instead of a deque<char> (which I suppose you are using)?

    On the other hand, you could do thequeue.push_back(yourstructobj.charmember); if you are using deque<char>.

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    16

    Yah!!

    That makes soo much sense. I feel soo silly now.
    Thanks eMMeMM....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting from C to C++
    By Taka in forum C++ Programming
    Replies: 5
    Last Post: 04-08-2009, 02:16 AM
  2. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  3. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  4. comparing fields in a text file
    By darfader in forum C Programming
    Replies: 9
    Last Post: 08-22-2003, 08:21 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 12:54 PM