C++ - 如何通过变异模板访问向量推入矢量的元素
我需要像这样调用C类对象 -
int main()
{
C<Pair<"x", A<int>>, Pair<"y", A<double>>, Pair<"z", B<int>>> c1;
C<Pair<"x", A<int>>, Pair<"y", A<double>>> c2;
}
到目前为止我有此代码 -
template <typename X>
class A
{
.....
};
template <typename Y>
class B
{
.....
};
template <typename S, typename T>
struct Pair // wrap a generic type
{
pair<S,T> p;
}
template <typename... P>
class C
{
tuple<Pair*...> v; // every time the class and type will differ??
public:
void func()
{
v.push_back(//all P in sequence);
//access the 1st and 2nd element of each pair in vector
}
};
如何按顺序推动所有P,然后访问C类中每个对的元素?
如果上述方法有故障,那么我可以使用哪种其他方式来调用C类,如上所述?
I need to call the C class object like this -
int main()
{
C<Pair<"x", A<int>>, Pair<"y", A<double>>, Pair<"z", B<int>>> c1;
C<Pair<"x", A<int>>, Pair<"y", A<double>>> c2;
}
I have this code so far -
template <typename X>
class A
{
.....
};
template <typename Y>
class B
{
.....
};
template <typename S, typename T>
struct Pair // wrap a generic type
{
pair<S,T> p;
}
template <typename... P>
class C
{
tuple<Pair*...> v; // every time the class and type will differ??
public:
void func()
{
v.push_back(//all P in sequence);
//access the 1st and 2nd element of each pair in vector
}
};
How can I push all P in sequence and then access the elements of each pair in class C?
If there is a fault in the above approach, then what other way I can use to be able call class C object like mentioned above?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论