
template <class CollectionType,class ItemType>class Test{public: CollectionType<ItemType> m_collection;}; 所以我可以这样做:
Test t = Test<vector,int>();t.m_collection<vector<int>> = vector<int>();
但这会产生
test.cpp:12: error: `CollectionType' is not a template解决方法 为什么不这样做呢?
template <class CollectionType>class Test{public: CollectionType m_collection;};Test t = Test<vector<int> >();t.m_collection = vector<int>(); 如果需要itemtype,可以使用CollectionType :: value_type.
编辑:响应您关于创建返回value_type的成员函数的问题,您可以这样做:
typename CollectionType::value_type foo();
您添加了typename,因为CollectionType尚未绑定到实际类型.所以它没有可以查找的value_type.
总结以上是内存溢出为你收集整理的您可以使用C模板指定集合类型和该类型的特化吗?全部内容,希望文章能够帮你解决您可以使用C模板指定集合类型和该类型的特化吗?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)