我做一个属性页,
在属性表的类声明里声明属性页,在构造函数里把属性页加入属性表.结果出错.如下Exam01Sheet.hclass CExam01Sheet : public CPropertySheet
{
...
public:
CExam01Dlg page1("page1");        // 21
CExam01Dlg page2("page2");        // 22
public:
CExam01Sheet(UINT nIDCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0);
CExam01Sheet(LPCTSTR pszCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0);
...
};
Exam01Sheet.cppCExam01Sheet::CExam01Sheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
{
this->AddPage(&page1);            // 23
this->AddPage(&page2);            // 24
}CExam01Sheet::CExam01Sheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
this->AddPage(&page1);            // 30
this->AddPage(&page2);            // 31
}
结果出错:
e:\mywork\exam01\exam01sheet.h(21) : error C2059: syntax error : 'string'
e:\mywork\exam01\exam01sheet.h(22) : error C2059: syntax error : 'string'
Exam01Sheet.cpp
e:\mywork\exam01\exam01sheet.h(21) : error C2059: syntax error : 'string'
e:\mywork\exam01\exam01sheet.h(22) : error C2059: syntax error : 'string'
E:\MYWORK\exam01\Exam01Sheet.cpp(23) : error C2276: '&' : illegal operation on bound member function expression
E:\MYWORK\exam01\Exam01Sheet.cpp(24) : error C2276: '&' : illegal operation on bound member function expression
E:\MYWORK\exam01\Exam01Sheet.cpp(30) : error C2276: '&' : illegal operation on bound member function expression
E:\MYWORK\exam01\Exam01Sheet.cpp(31) : error C2276: '&' : illegal operation on bound member function expression请大侠们帮忙看看是哪里错了.谢了哈..

解决方案 »

  1.   

    把CExam01Dlg的构造函数贴上来看看。
      

  2.   

    21、22是不是用的UNICODE字符集?用CExam01Dlg page1(_T("page1"));
    另外检查下CExam01Dlg的构造函数。还是有CExam01Dlg是不是从CPropertyPage继承下来的。
    上面的都OK了的话,应该就不会有23、24、30、31这些错误。
      

  3.   

    好的..exam01Dlg.hclass CExam01Dlg : public CPropertyPage
    {
    ...
    public:
    CExam01Dlg(UINT nIDTemplate, UINT nIDCaption = 0);
    CExam01Dlg(LPCTSTR lpszTemplateName, UINT nIDCaption = 0);
    ...
    };
    exam01Dlg.cppCExam01Dlg::CExam01Dlg(UINT nIDTemplate, UINT nIDCaption)
    : CPropertyPage(nIDTemplate, nIDCaption)
    {
    //{{AFX_DATA_INIT(CExam01Dlg)
    // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }CExam01Dlg::CExam01Dlg(LPCTSTR lpszTemplateName, UINT nIDCaption)
    : CPropertyPage(lpszTemplateName, nIDCaption)
    {
    //{{AFX_DATA_INIT(CExam01Dlg)
    // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }
    我这个属性页类是从对话框内改出来的.不知道是不是哪里改错了.记得以前似乎就是这么改的.
      

  4.   

    按2楼说的改成
    CExam01Dlg page1(_T("page1")); 
    后还是不行发现一个问题.
    21,22的page1,page2应该是变量名,而在类视图里显示为函数名.
    是我写错了还是什么地方出错了?
      

  5.   

    类里面不能初始化(或构造)成员变量,要在类的构造函数中初始化(或构造)。这样写:
    class CExam01Sheet : public CPropertySheet
    {
    public:
        CExam01Sheet();
        CExam01Dlg page1;
        CExam01Dlg page2;
    // ...
    };CExam01Sheet::CExam01Sheet() : page1(CExam01Dlg("page1")), page2(CExam01Dlg("page2"))
    {
    }
      

  6.   

    应该是这样:
    class CExam01Sheet : public CPropertySheet
    {
    public:
        CExam01Sheet();
        CExam01Dlg page1;
        CExam01Dlg page2;
    // ...
    };CExam01Sheet::CExam01Sheet() : page1("page1"), page2("page2")
    {
    }
      

  7.   

    晕,看走眼了。呵呵。类声明中这样写当然不行CExam01Dlg page1("page1");按楼上的即可。