samedi 30 mars 2019

How to change `void *` type to `string` type

I have supplied code from a demo and the type associated with the fonts are of type void *.

Here is the type of the font as declared in vscode

#define GLUT_BITMAP_HELVETICA_18 (&glutBitmapHelvetica18)
Expands to:

(&glutBitmapHelvetica18)

I am trying to write a quick little conditional to check whether the font is from a list or not.

if (find(begin(fonts), end(fonts), reinterpret_cast<char*>(font) ) != end(fonts))

I am using an iterator to iterate through an array of strings.

    array<string, 7> fonts = { 
      "GLUT_BITMAP_TIMES_ROMAN_24", 
      "GLUT_BITMAP_TIMES_ROMAN_10", 
      "GLUT_BITMAP_HELVETICA_12",
      "GLUT_BITMAP_HELVETICA_10",
      "GLUT_BITMAP_8_BY_13",
      "GLUT_BITMAP_9_BY_15" };

My issue is that since all the elements in that array are strings it is throwing a type error between the void * and the string. I am not too sure how to cast the type to a string or if there is a better way of checking if that void * is within the array or even a simple list of possible options.

Aucun commentaire:

Enregistrer un commentaire