刚学vc不久,使用的是vc6.0_sp6 + WinXP_sp2,我是照着孙鑫老师的视频做练习,可是到这"pDC->SetPixel(((CGraphic*)m_ptrArray.GetAt(i))->m_ptOrigin, RGB(255,0,0));"就报错.如下:Debug Assertion Failed!
...
For information on how your program can casuse an assertion failure,see the Visual C++ documentation on aserts.....然后程序就终止,转到调试模式下,我ASM又看不懂,郁闷!//////////////////////////////////////////
//下面是代码
//////////////////////////////////////////
void CGraphicView::OnDraw(CDC* pDC)
{
  CGraphicDoc* pDoc = GetDocument();
  ASSERT_VALID(pDoc);
  // TODO: add draw code for native data here
  CBrush* pBrush = CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
  pDC->SelectObject(pBrush);

  for(int i=0; i<=m_ptrArray.GetSize(); ++i)
  {
    //下面这句出错,难道是系统的问题.
    switch(((CGraphic*)m_ptrArray.GetAt(i))->m_nDrawType)
    { 
      case 1:
        //pDC->SetPixel(((CGraphic*)m_ptrArray.GetAt(i))->m_ptOrigin, RGB(255,0,0));
        break;
      case 2:
        break;
      default:
        break;
   }
  }
}
// 顺便问一下,这个Dlg构造函数中":"后面部分是什么意思,该怎样理解?
CFasDlg::CFasDlg(CWnd* pParent /*=NULL*/): CDialog(CFasDlg::IDD, pParent)
{
}在此先行谢谢了~~~

解决方案 »

  1.   

    1.你在调试时,报ASSERT错误后,点重试,看看那个语句产生了assert2.执行基类CDialog的构造函数。
      

  2.   

    for(int i=0; i<=m_ptrArray.GetSize(); ++i)
    change to 
     for(int i=0; i<=m_ptrArray.GetSize(); i++)I am sure you already know the difference.
      

  3.   

    CFasDlg::CFasDlg(CWnd* pParent /*=NULL*/)pParent: 设置对话框的父窗口
      

  4.   

    http://community.csdn.net/Expert/topic/4523/4523125.xml?temp=.850918
      

  5.   

    CFasDlg::CFasDlg(CWnd* pParent /*=NULL*/): CDialog(CFasDlg::IDD, pParent)
    {
    }
    -----------------------
    在这里执行CDialog的构造函数,并且把CFasDlg中的pParent参数传给CDialog的构造函数。
      

  6.   

    CDialog(CFasDlg::IDD, pParent)
    是执行基类构造
     for(int i=0; i<=m_ptrArray.GetSize(); ++i)这个地方的++i改i++;
      

  7.   

    m_ptrArray数组是在什么地方设置大小的?
      

  8.   

    m_ptrArray
    声明了没有?
      

  9.   

    回复人: jiangsheng(蒋晟.Net[MVP]) ( ) 信誉:285  2006-1-19 6:54:14  得分: 0  
    for(int i=0; i<=m_ptrArray.GetSize(); ++i)
    change to 
     for(int i=0; i<=m_ptrArray.GetSize(); i++)I am sure you already know the difference.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    谢谢,不过改过来也不行,我想你说的的意思是数组越界.于是,我将i的初始值改为1,能调通了.
     for(int i=1; i<=m_ptrArray.GetSize(); i++) 
    //or
     for(int i=1; i<=m_ptrArray.GetSize(); ++i) 
    难道CPtrArray的第一个元素下标为1么?不明白.
    第一次用CPtrArray这个类,我再看看MSDN.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ~回复人: syy64(太平洋) ( ) 信誉:145  2006-01-19 15:39:00  得分: 0  
       m_ptrArray数组是在什么地方设置大小的?
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //在OnLButtonUp中这样设置的
    CGraphic* pGraphic = new CGraphic(m_nDrawType, m_ptOrigin, point);
    m_ptrArray.Add(pGraphic);
      

  10.   

    i改为1调通运行,一旦窗口重绘WM_PAINT,程序又挂了.迷茫中
      

  11.   

    CObject* GetAt( int nIndex ) const;
    Return Value
    The CObject pointer element currently at this index.
    Parameters
    nIndex
    An integer index that is greater than or equal to 0 and less than or equal to the value returned by GetUpperBound.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    问题已经解决果然是下标越界.大家都忽略了 i<=m_ptrArray.GetSize(), 多了一个"=".天天vb拖控件,脑袋傻掉了/////////////////////////////////
    CDialog(CFasDlg::IDD, pParent)
    是执行基类构造我是想了解一下细节~~???????
    12:30睡觉前结贴~
      

  12.   

    for(int i=0; i<=m_ptrArray.GetSize(); ++i)改成
      for(int i=0; i < m_ptrArray.GetSize(); ++i)CFasDlg::CFasDlg(CWnd* pParent /*=NULL*/): CDialog(CFasDlg::IDD, pParent)
    类成员变量初始化的方式调用基类构造函数,C++类的基础语法。