[英]How to forward declare an aliased template in c++
I have the following aliased template:我有以下别名模板:
#include <vector>
template <typename T>
using MyVector = std::vector <T>;
How can i forward declare MyVector
?我如何转发声明MyVector
?
template <typename T>
class MyVector;
does not work for me.对我不起作用。
You cannot forward declare an using declaration.您不能转发声明 using 声明。
Anyway, you can declare forward a sort of traits as it follows:无论如何,您可以按如下方式声明一种特征:
#include <type_traits>
#include <vector>
template<typename>
struct MyStuff;
template<typename T>
auto f() { return typename MyStuff<T>::MyVector{}; }
template<typename T>
struct MyStuff {
using MyVector = std::vector<T>;
};
int main() {
static_assert(std::is_same<decltype(f<int>()), std::vector<int>>::value, "!");
}
You might be able to get away with making it a type, which you will be able to forward-declare:您可以将其设为一种类型,您可以预先声明它:
template <typename T>
struct MyVector: std::vector<T> {};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.