Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 分配器:“;没有可用的成员;。我怎样才能解决这个问题?_C++_Templates_Vector_Allocation - Fatal编程技术网

C++ 分配器:“;没有可用的成员;。我怎样才能解决这个问题?

C++ 分配器:“;没有可用的成员;。我怎样才能解决这个问题?,c++,templates,vector,allocation,C++,Templates,Vector,Allocation,因此,在下面的代码行中,我有IntelliSense警告:“没有可用的成员”。发生了什么?在正常情况下,似乎有一些选项,如“分配”、“取消分配”等 名称空间MyLib { 模板 类向量 { 私人: 标准:尺寸和容量; 标准:尺寸大小; T*arr; 公众: 类型定义分配器分配器类型; typedef矢量型; 模板 使用AllocTraits=std::allocator\u特征; 分配器特征://这里! 实际上,std::allocator\u traits::也不起作用。但在这种情况下也起作

因此,在下面的代码行中,我有IntelliSense警告:“没有可用的成员”。发生了什么?在正常情况下,似乎有一些选项,如“分配”、“取消分配”等

名称空间MyLib
{
模板
类向量
{
私人:
标准:尺寸和容量;
标准:尺寸大小;
T*arr;
公众:
类型定义分配器分配器类型;
typedef矢量型;
模板
使用AllocTraits=std::allocator\u特征;
分配器特征://这里!
实际上,
std::allocator\u traits::
也不起作用。但在这种情况下也起作用(就像
std::allocator\u traits::
):

模板<
类型名T,
模板类分配器=std::Allocator>//使用std::Allocator作为默认分配器
std::唯一的\u ptr移动\u和\u分配器(
T&&stack_对象,分配器分配器=分配器()
{
使用AllocTraits=std::allocator\u特征;
std::allocator_traits::allocate(allocator,1);//在这里工作正常
Visual Studio 2019

我怀疑您想要。如果Intellisense对可能的模板参数有想法,它可以提供更好的提示

namespace MyLib
{
    template <typename T,
        template <typename Y> class Allocator = std::allocator>
    class Vector
    {
    private:
        std::size_t capacityV;
        std::size_t sizeV;
        T* arr;
    public:
        typedef Allocator<T> AllocatorType;
        typedef Vector<T, Allocator> VectorType;
        template<typename T>
        using AllocTraits = std::allocator_traits<Allocator<T>>;

        std::allocator_traits<Allocator<T>>::    //HERE!
template <
    typename T,
    template <typename Y> class Allocator = std::allocator> // use std::allocator as default allocator
std::unique_ptr<T, std::function<void(T*)>> move_with_allocator(
    T&& stack_object, Allocator<T> allocator = Allocator<T>())
{
    using AllocTraits = std::allocator_traits<Allocator<T>>;
    std::allocator_traits<std::allocator<T>>::allocate(allocator, 1);    //WORKING FINE HERE