Const incorrectness
<p>Why am I getting this error:<br>
<strong>Error 1   error C2662: 'Allocator::Allocate' : cannot convert 'this' pointer from 'const Allocator' to 'Allocator &amp;'</strong> ?  </p>

<p>Thats code:  </p>

<pre><code>/*Allocator.h*/
    /*Not finished yet but working*/
    #pragma once
    template&lt;class T&gt;
    class Allocator
    {
    public:
        //typedef T value_type;
        typedef T* pointer;
        pointer Allocate(std::size_t count);
        pointer Construct(void* address, const pointer obj);
        template&lt;class FwdIter&gt;
        void Destroy_(FwdIter first,FwdIter last);
        void Deallocate_(void* where);
        Allocator();
        ~Allocator();

    private:
        void Destroy_(const T* obj);


    };
/*Allocator_impl.hpp*/
#pragma once
#include "StdAfx.h"
#include "Allocator.h"

template&lt;class T&gt;
Allocator&lt;T&gt;::Allocator()
{
}


template&lt;class T&gt;
Allocator&lt;T&gt;::~Allocator()
{
    /*Destroy();
    Deallocate();*/
}

template&lt;class T&gt;
typename Allocator&lt;T&gt;::pointer Allocator&lt;T&gt;::Allocate(std::size_t count)
{
    return static_cast&lt;pointer&gt;(::operator new(sizeof(value_type) * count));
}

template&lt;class T&gt;
typename Allocator&lt;T&gt;::pointer Allocator&lt;T&gt;::Construct(void* address, const pointer obj)
{
    return new (address) T(*obj);
}

//template&lt;class T&gt;
//void Allocator&lt;T&gt;::Destroy()
//{
//  //Destroy_(addressBegin_, addressBegin_ + size_);
//}

template&lt;class T&gt;
void Allocator&lt;T&gt;::Destroy_(const T* obj)
{
    obj-&gt;~T();
}

template&lt;class T&gt;
template&lt;class FwdIter&gt;
void Allocator&lt;T&gt;::Destroy_(FwdIter first,FwdIter last)
{
    while (first != last)
    {
        Destroy_(&amp;*first);
        ++first;
    }
}

template&lt;class T&gt;
void Allocator&lt;T&gt;::Deallocate_(void* address)
{
    ::operator delete(address);
}

//template&lt;class T&gt;
//void Allocator&lt;T&gt;::Deallocate()
//{
//  //Deallocate_(addressBegin_);
//}
/*Toy.h*/
        #pragma once
    #include "Allocator_impl.hpp"


    /*As a base to managed memory*/
    template&lt;class T, class A = Allocator&lt;T&gt;&gt;
    class ToyBase
    {   
        typedef T* pointer;
    private:
        A alloc_;
    protected:
//--------------------------------------COMMENT HERE
            pointer Allocate(const std::size_t)const;&lt;------------When invoking this fnc from
        explicit ToyBase();
        virtual ~ToyBase();
    };

    template&lt;class T, class A&gt;
    ToyBase&lt;T,A&gt;::ToyBase()
    {}


    template&lt;class T, class A&gt;
    ToyBase&lt;T,A&gt;::~ToyBase()
    {}
    //--------------------------------------AND COMMENT HERE
    template&lt;class T, class A&gt;
    typename ToyBase&lt;T,A&gt;::pointer ToyBase&lt;T,A&gt;::Allocate(const std::size_t count)const
    {
        return alloc_.Allocate(count);&lt;-----------here
    }
    /*
But when I remove const from fnc decl. it works. I do not understand it as I do not change an object merely invoke fnc on its member.
*/



    template&lt;class T&gt;
    class ToyRepresentation : private ToyBase&lt;T&gt;
    {
    public:
        typedef T value_type;
        typedef T* pointer;
        ToyRepresentation(const std::size_t = 0);
        void Push(T*);
        void Pop();
        void GetSize()const;
        void GetCapacity()const;
        void SetCapacity(const std::size_t);
        void Reset();
    private:
        pointer data_;
        std::size_t size_;
        std::size_t capacity_;
        static unsigned TOTAL_; //total number of created objects
    };

    template&lt;class T&gt;
    unsigned ToyRepresentation&lt;T&gt;::TOTAL_ = 0;


    template&lt;class T&gt;
    ToyRepresentation&lt;T&gt;::ToyRepresentation(const std::size_t count = 0): ToyBase&lt;T&gt;(), data_(Allocate(count)), size_(0), capacity_(count)
    {
    }

    /*tmain*/ 
#include "stdafx.h"
#include "Toy.h" 
int _tmain(int argc, _TCHAR* argv[])
{
    try
    {
        ToyRepresentation&lt;int&gt; t;
    }
    catch(const std::exception&amp;)
    {
    }
    return 0;
}
</code></pre>

<p>Comments to interesting lines are marked in code. Thanks.</p>
