c++ - What's the best "type renaming" method? -


if wanted rename std::string type simpler , more naturally looking string, of these 2 methods should use (based on performance , standard)

should rename preprocessed directive

#define string std::string 

or type definition

typedef std::string string; 

what's performant method? more familiar , recognized community?

just

using std::string; 

if want different name, e.g.

using string = std::string; 

avoid macros, don't respect scopes , evil™.

for example, proposed macro

#define string std::string 

… yields formal undefined behavior if include standard library header, because defines name used standard library.

c++11 §17.6.4.2.2/1 [macro.names]:

translation unit includes standard library header shall not #define or #undef names declared in standard library header.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo