我在vc7里面使用:
CEdit *pEdit = (CEdit *)(this->GetDlgItem(IDC_EDIT1));
这样可以正确得到Edit的指针,
但是使用:
CEdit *pEdit = dynamic_cast<CEdit *>(this->GetDlgItem(IDC_EDIT1));
得不到正确的指针,得出是NULL,
已经把项目属性里面编译的选项启用运行时类型信息设置为是(/GR)了.

解决方案 »

  1.   

    dynamic_cast Operator
    C++ Specific dynamic_cast < type-id > ( expression )The expression dynamic_cast< type-id >( expression ) converts the operand expression to an object of type type-id. The type-id must be a pointer or a reference to a previously defined class type or a "pointer to void". The type of expression must be a pointer if type-id is a pointer, or an l-value if type-id is a reference.
      

  2.   

    you should use reinterpret_cast!
      

  3.   

    我经常用dynamic_cast,没发现过这个问题
      

  4.   

    reinterpret_cast!

    (CEdit *)(this->GetDlgItem(IDC_EDIT1));
    也没有太大的区别,人家老朱就要dynamic_cast^_^
      

  5.   

    GetDlgItem返回本来就是一个CWnd(真正的CWnd,不是CEdit的多态),所以不能用dynamic_cast转换。