i know that this question have been answered here already : C++ string to enum but i'm really lost on how to use it so please don't be rude ;)
I want to convert my string in a tEnumCouleur.. I have :
#pragma once
#include <map>
#include <cassert>
class EnumCouleur
{
public :
enum tEnumCouleur{BLACK,BLUE,RED,GREEN,YELLOW,CYAN};
std::map<std::string, tEnumCouleur> xmap = boost::assign::map_list_of<std::string, tEnumCouleur>(BLACK, "BLACK")(BLUE, "BLUE")(GREEN, "GREEN");
//Getting an error with the "=" saying it's an unautorized initialisation
//also getting an error at the end of std::map<std::string, tEnumCouleur> xmap = boost::assign::map_list_of<std::string, tEnumCouleur>, asking for ";"
// static car ce get ne sappele pas sur un objet EnumCouleur (il sera toujours le même) cout<<EnumCouleurs::c_Str(v)
static const char * c_Str(tEnumCouleur l) {
return strEnumCouleur[l];}
std::map<std::string, tEnumCouleur> xmap;
private :
static char * strEnumCouleur[];
//EnumCouleur();
};
and a .cpp to allow me to convert enum into string :
#include "EnumCouleur.h"
#include <string>
char * EnumCouleur::strEnumCouleur[] = {
"BLACK","BLUE","RED","GREEN","YELLOW","CYAN"
};
i ve tried both things that i found on the topic i linkd :
std::map<std::string, tEnumCouleur> xmap = boost::map_list_of("A", A)("B", B)("C",C);
struct responseHeaderMap : public std::map<std::string, tEnumCouleur>
{
responseHeaderMap()
{
this->operator[]("BLACK") = BLACK;
this->operator[]("BLUE") = BLUE;
this->operator[]("RED") = RED;
this->operator[]("GREEN") = GREEN;
this->operator[]("YELLOW") = YELLOW;
this->operator[]("CYAN") = CYAN;
};
~responseHeaderMap(){}
};
I really don't know how to use it.. let's say my program got a string from a textdocument. i'm sure that this string is correct. I want to make as an tEnumCouleur, in way to fit a contructor :
Segment( const Point p1, const Point p2, EnumCouleur::tEnumCouleur v);
How do i do that please ?