Use value of string for wide string when declaring constants in C++

Using defines I am able to declare a wide string that uses the value of regular string as follows:

#define MY_STRING "my value"
#define MY_WIDE_STRING L"" MY_STRING

How can I achieve the same but with member variables and a initialization list - i.e. something like this...

class MyClass
{
    private:
         const std::string MY_STRING
         const std::wstring MY_WIDE_STRING
    public:
         MyClass():MY_STRING("my value"), MY_WIDE_STRING(L"" MY_STRING)
         {
         }

Thanks

Answers


A possible solution:

#define MY_VALUE "my value"

class MyClass
{
  private:
    const std::string MY_STRING
    const std::wstring MY_WIDE_STRING
  public:
    MyClass():MY_STRING(MY_VALUE), MY_WIDE_STRING(L"" MY_VALUE)
    {}
  // ...
};

I assume the reason you need both the char and wchar_t versions of the same string are because you're calling different libraries that you don't control. Rather than keeping two copies of the string in sync, it's probably better to do a run-time conversion from one to the other when you must have the other version.


Need Your Help

Unions as Base Class

c++ inheritance unions language-lawyer

The standard defines that Unions cannot be used as Base class, but is there any specific reasoning for this? As far as I understand Unions can have constructors, destructors, also member variables,...

Java and Spring back-end with Ruby (RhoMobile) front-end security

java spring-security rhomobile shiro

I am currently building a mobile application using RhoMobile. The application will simply be calling a bunch of REST web services. The back-end REST services are written in Java + Spring. I was won...