首页 > 解决方案 > 分配器:“没有可用的成员”。我该如何解决?

问题描述

因此,在呈现代码的下一行,我有 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!

其实std::allocator_traits<std::allocator<T>>::也行不通。但在这些情况下有效(就像std::allocator_traits<Allocator<T>>::):

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

视觉工作室 2019

标签: c++templatesvectorallocation

解决方案


我怀疑你想要Template Intellisense。如果 Intellisense 对可能的模板参数有所了解,它可以提供更好的提示。


推荐阅读