在CStuDoc类里面定义了两个成员变量
public:
POSITION m_position;CObList m_studentList;
在CStuView类里面加了消息处理函数,具体见如下代码:
void CStuView::OnBnSave()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CStudent* pStudent=new CStudent();
pStudent->m_strName=m_strName;
pStudent->m_nGrade=m_nGrade;
m_studentList.AddTail(pStudent);
}
在编译时出现错误:
error C2065: 'm_studentList' : undeclared identifier
error C2228: left of '.AddTail' must have class/struct/union type
我在CStuView.cpp类中加了#include "StuDoc.h"头文件
按理说不应该报变量没有定义的错误的呀。郁闷死了,有谁遇到相似的问题的,帮帮忙阿。其中CStudent类定义
class CStudent:public CObject
{
DECLARE_DYNAMIC(CStudent)
public:
CString m_strName;
int m_nGrade; CStudent()
{
m_nGrade = 0;
}
}
public:
POSITION m_position;CObList m_studentList;
在CStuView类里面加了消息处理函数,具体见如下代码:
void CStuView::OnBnSave()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CStudent* pStudent=new CStudent();
pStudent->m_strName=m_strName;
pStudent->m_nGrade=m_nGrade;
m_studentList.AddTail(pStudent);
}
在编译时出现错误:
error C2065: 'm_studentList' : undeclared identifier
error C2228: left of '.AddTail' must have class/struct/union type
我在CStuView.cpp类中加了#include "StuDoc.h"头文件
按理说不应该报变量没有定义的错误的呀。郁闷死了,有谁遇到相似的问题的,帮帮忙阿。其中CStudent类定义
class CStudent:public CObject
{
DECLARE_DYNAMIC(CStudent)
public:
CString m_strName;
int m_nGrade; CStudent()
{
m_nGrade = 0;
}
}
可以参考下面的例子,不要照抄.
class CDocument : public xxx
{
public:
COblist& GetStudentList()
{
return m_studentList;
}
.........
}
//
void CStuView::OnBnSave()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CStudent* pStudent=new CStudent();
pStudent->m_strName=m_strName;
pStudent->m_nGrade=m_nGrade;
CDocument* pDoc = dynamic_cast<CDocument*>(GetDocument());
if(pDoc)
{
pDoc->GetStudentList().AddTail(pStudent);
}
}
CObList m_studentList是public类型阿,
不是说public类型的可以被所有的访问吗?指教,不太清楚
===================================
楼主还是找本C++基础书看看吧,public类型是可以被所有的访问,但是这里的m_studentList是Doc类的成员变量,用的时候一定要 Doc对象.m_studentList,才能引用,而且,Doc类可以有很多实例,不同的实例有不同的m_studentList.你用的方法对全局变量适用.
==========
GetDocument()->m_studentList.AddTail(pStudent);