سؤال

I have a queue that push CAtlArray but it returns

cannot access private member declared in class 'ATL::CAtlArray<E>' with

[

 E=BYTE

]

My code is

      CAtlArray<BYTE> mybuffer; //Fulled with data somewhere
      std::queue< CAtlArray<BYTE> > myqueue;
      myqueue.push(mybuffer);
هل كانت مفيدة؟

المحلول

As mentioned in the comment, most ATL containers (at least all the ones I've worked with, but I can't state this with 100% guarantee) don't provide a copy constructor, whereas stl containers being non-intrusive keep a copy of the contained object, so e.g. when generating the template code for push() the compiler cannot call the copy constructor and you get the error.

If you just need a list container, you can use another ATL container to store the ATL array, it's not the prettiest code in the world, since ATL also uses copy constructors and inserting another ATL container in a ATL container is not straightforward, but this demonstrates how to achieve what you need.

#include <atlcoll.h>
#include <queue>
#include <iostream>

using namespace std;

int main(int argc, char** argv)
{
    CAtlArray<BYTE> buffer;
    buffer.Add('a');
    buffer.Add('b');
    buffer.Add('c');
    CAtlList<CAtlArray<BYTE>> list;
    list.GetAt(list.AddTail()).Copy(buffer);
    CAtlArray<BYTE> queueHead;
    queueHead.Copy(list.GetAt(list.GetHeadPosition()));
    list.RemoveHeadNoReturn();
    std::cout << queueHead.GetAt(0) << " " << queueHead.GetAt(1) << " " << queueHead.GetAt(2);
    return 0;
}

If STL is a must have, you need to either specialize the template or seek other approaches.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top