【发布时间】: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<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
Visual Studio 2019
【问题讨论】:
标签: c++ templates vector allocation