4

In the following example, I would like to remove the std::wstring(std::widen(...)) part, but the '#' macro only returns a char string literal -- is there any way to accommodate a wchar?

#define FOO_MACRO(className)\
struct className##Factory : public OtherClass {\
// does some stuff here\
} className##Factory;\
someMap->add(std::wstring(std::widen(#className), className##Factory)))

How would I do the same thing using wchar?

joce
  • 9,624
  • 19
  • 56
  • 74
ash
  • 3,354
  • 5
  • 26
  • 33
  • 1
    Not sure I entirely understand what you want to achieve, as I haven't used wchar, but why oh why oh why are you using macros for this? – Alex Chamberlain Feb 19 '13 at 20:49
  • The code that you posted does not work like that. It will compile to error: Identifier someText_not_a_string not found. – Öö Tiib Feb 19 '13 at 20:53
  • possible duplicate of [Standard macro to promote string literal to wchar\_t in VC++](http://stackoverflow.com/questions/11875774/standard-macro-to-promote-string-literal-to-wchar-t-in-vc) – Michael Kristofik Feb 19 '13 at 21:10
  • perhaps I oversimplified what I am trying to accomplish -- i have edited it with more detail. – ash Feb 19 '13 at 21:14
  • One problem is that you seem to be trying to call `std::widen` with two arguments when it only takes one. Probably your parentheses are in the wrong place. – Chris Dodd Feb 19 '13 at 21:55
  • corrected... that was a typo – ash Feb 19 '13 at 22:25

1 Answers1

8

You use an L prefix on the string literal to make a wchar string literal:

#define CAT(A, B)   A##B
#define WSTRING(A)  CAT(L, #A)
Chris Dodd
  • 119,907
  • 13
  • 134
  • 226