Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试将成员变量传递给模板。例如,如果我有以下内容:
struct MyStruct { MyType MyMember; }
我该怎么做:
MyType MyVar = MyTemplate<MyStruct, &MyStruct::MyMember, MyType>();
我试图四处搜索,但没有找到任何可以准确解释如何实现这一目标的东西......对不起,如果这是一个愚蠢的问题,我对 c++ 很陌生......
欢迎任何帮助!
这里有一些东西:
template< typename Class, typename MemberType, MemberType Class::*Member > struct my_template;
你可以像这样使用它:
my_template< MyStruct, MyType, &MyStruct::MyMember > _;