【问题标题】:Allocators: "No members available". How can I fix that?分配器:“没有可用的成员”。我该如何解决?
【发布时间】:2019-10-08 13:36:22
【问题描述】:

因此,在显示代码的下一行,我有 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&lt;std::allocator&lt;T&gt;&gt;:: 也不起作用。但在这些情况下有效(就像std::allocator_traits&lt;Allocator&lt;T&gt;&gt;::):

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

Visual Studio 2019

【问题讨论】:

    标签: c++ templates vector allocation


    【解决方案1】:

    我怀疑你想要Template Intellisense。如果 Intellisense 知道可能的模板参数,它可以提供更好的提示。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-10
      • 2023-02-10
      • 2021-09-04
      • 2021-03-26
      • 2014-10-28
      • 1970-01-01
      • 2013-12-26
      相关资源
      最近更新 更多