0

I have this in my c++ code:

std::vector<WCHAR> sText(4096);

I want to simplify it into a macro so I'm not always typing std::vector<WCHAR> every time. I can't figure out how to shorthand this into a macro. Any help is appreciated.

JeffR
  • 765
  • 2
  • 8
  • 23
  • 3
    TL;DR of the dupe: `using your_new_name_here = std::vector;` – NathanOliver Jul 30 '19 at 13:20
  • For a variable named `sText` and which contains characters, wouldn't a *string* be better? As in `std::wstring sText;`? – Some programmer dude Jul 30 '19 at 13:21
  • 3
    And a general tip for creating shorthand names of types: Don't. They tend to make the code *harder* to read and understand. Either you need to make the name descriptive enough that it's often longer than the original type it's supposed to replace, or you need to add some semantic meaning to the alias. – Some programmer dude Jul 30 '19 at 13:23
  • if I use `using your_new_name_here = std::vector`, how do I tell it what size to use? – JeffR Jul 30 '19 at 13:27
  • It's just another name. Use it the same. – Kenny Ostrom Jul 30 '19 at 13:34
  • Some additional reading on macros focusing on why and where you should avoid them: [Why are preprocessor macros evil and what are the alternatives?](https://stackoverflow.com/questions/14041453/why-are-preprocessor-macros-evil-and-what-are-the-alternatives) – user4581301 Jul 30 '19 at 13:53
  • This name is tiny. Just type it. It's easy. – Lightness Races in Orbit Jul 30 '19 at 14:03

0 Answers0