简体   繁体   English

Qt的moc / C ++ 11是否具有等效于C#的nameof()运算符?

[英]Does Qt's moc/C++11 have an equivalent of C#'s nameof() operator?

Does Qt's moc/C++11 have an equivalent of C#'s nameof() operator? Qt的moc / C ++ 11是否具有等效于C#的nameof()运算符? Qt has the moc system which is/does some kind of reflection but I can't figure out how get the variable name like C#'s nameof() . Qt有一个moc系统,它正在/进行某种反射,但是我不知道如何获得像C#的nameof()这样的变量名。 Is this possible? 这可能吗?

This is not possible with C++ 11, because it is only possible with language / compiler support. 对于C ++ 11,这是不可能的,因为只有在语言/编译器支持下,才有可能。 It also has nothing to do with reflection (at run time) because it gives you the name of an identifier during compile time. 它也与反射(在运行时)无关,因为它在编译时为您提供了标识符的名称。

If your compiler supports C++17, then this library should do everything you want: https://github.com/Neargye/nameof 如果您的编译器支持C ++ 17,则此库应执行您想要的所有操作: https : //github.com/Neargye/nameof

See some more examples from the library author at https://www.reddit.com/r/cpp/comments/b3spr5/nameof_operator_for_modern_c_simple_name_of_a/ https://www.reddit.com/r/cpp/comments/b3spr5/nameof_operator_for_modern_c_simple_name_of_a/上查看库作者的其他示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM