[使用关键字的C ++类型别名

问题描述 投票:0回答:1

是否可以在c ++中用using关键字定义这种类型的别名?语法如何?我尝试过using const_type = typename const T::type无效。

template <typename T>
    class DoubleBuffer {
    typedef T value_type;
    typedef T& reference;
    typedef T const & const_reference;
    typedef T* pointer;

    const_reference operator[](const size_t pos){
        ...
    }
};
c++ c++17 typedef type-alias
1个回答
0
投票

是,在C ++ 11及更高版本中:

template <typename T>
class DoubleBuffer {
    using value_type = T;
    using reference = T&;
    using const_reference = T const &;
    using pointer = T*;
    ...
};

Live Demo

© www.soinside.com 2019 - 2024. All rights reserved.