-1

I am doing a small project of drawing tool.

I use line to draw a polygon, so I use CList<CPoint,CPoint> m_Points to store the end point of each line.

Here is my code:

void CDrawToolView::OnLButtonUp(UINT nFlags, CPoint point)
{
   .
   .
   .
   CList<CPoint,CPoint> m_Points; 
   m_Points.AddTail(point);
   . 
   .
   .
}

And I want to pass the points to a dialog. In the calling function:

void CDrawToolView::OnEditProperty()
{
    CPropertyDlg dlg;  
    dlg.Points = m_Points;
    if (dlg.DoModal() == IDOK)
    {   
        m_Points = dlg.Points;
    }
}

Then in the dialog, when clicking OK, read all the points from CList<CPoint,CPoint> Points:

void CPropertyDlg::OnBnClickedOk()
{
    CList<CPoint,CPoint> Points; 
    Points.AddTail(polypoint);
    POSITION pos = Points.GetHeadPosition();
    while( pos != NULL )
    {
       int i = 0;
       element = Points.GetNext(pos);
       polygon_x[i] = element.x;
       polygon_y[i] = element.y;
       i ++;
    }
}

When running program, CObject::operator =' : cannot access private member declared in class 'CObject' , how can I fix that problem?

Besides, can I use this method to pass points to the dialog?

Qingyao Li
  • 173
  • 2
  • 11
  • MFC: ah, so glad I don't have to wear that hair-shirt – Mitch Wheat Sep 08 '13 at 13:50
  • Harsh as it may sound, this is not the type of question to ask on stackoverflow. You have asked several questions all revolving around the same theme: How to pass complex data in C++. I would suggest to pick up a good introductory [book on C++](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) and work through that. – IInspectable Sep 08 '13 at 13:58

1 Answers1

0

Declare m_Points member of CPropertyDlg as CList<CPoint,CPoint>* and pass pointer to this dialog:

void CDrawToolView::OnEditProperty()
{
    CPropertyDlg dlg;  
    dlg.Points = &m_Points;
    if (dlg.DoModal() == IDOK)
    {   
        //m_Points = dlg.Points;   // not necessary because Points is changed in-place
    }
}

The problem in your existing code, that you are trying to pass CList by value, which requires copying the whole object. This is not allowed by MFC authors by making operator= private.

BTW, if you are trying to implement drawing functionality, check out MFC sample DRAWCLI.

Alex F
  • 42,307
  • 41
  • 144
  • 212