//Reg.cpp中#include"CStudent.h"CTypedPtrList<CObList,CStudent*> lists;
void CReg::New(CString * array)
{
CStudent *stu = new CStudent;
stu->ChangePrivate(array);
lists.AddTail(stu);
}其中CStudent在CStudent.h定义
产生一排类似下面的错误
怎解?我分明没在Reg.cpp中定义CStudent
Course_MFC error LNK2005: "public: __thiscall CStudent::CStudent(void)" (??0CStudent@@QAE@XZ) 已经在 Reg.obj 中定义
void CReg::New(CString * array)
{
CStudent *stu = new CStudent;
stu->ChangePrivate(array);
lists.AddTail(stu);
}其中CStudent在CStudent.h定义
产生一排类似下面的错误
怎解?我分明没在Reg.cpp中定义CStudent
Course_MFC error LNK2005: "public: __thiscall CStudent::CStudent(void)" (??0CStudent@@QAE@XZ) 已经在 Reg.obj 中定义
2 检查程序,应该是程序的问题,估计是不小心的错误
源程序是这样的,我发现不到错误,请帮忙看看:// Reg.cpp : implementation file
//#include "stdafx.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CReg dialogCReg::CReg(CWnd* pParent /*=NULL*/)
: CDialog(CReg::IDD, pParent)
{
//{{AFX_DATA_INIT(CReg)
//}}AFX_DATA_INIT
}
void CReg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CReg)
DDX_Control(pDX, IDOK, m_ok);
DDX_Control(pDX, IDC_EDIT5, m_grade);
DDX_Control(pDX, IDC_EDIT4, m_age);
DDX_Control(pDX, IDC_COMBO2, m_sex);
DDX_Control(pDX, IDC_EDIT3, m_password);
DDX_Control(pDX, IDC_EDIT2, m_num);
DDX_Control(pDX, IDC_EDIT1, m_name);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CReg, CDialog)
//{{AFX_MSG_MAP(CReg)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
ON_EN_CHANGE(IDC_EDIT3, OnChangeEdit3)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CReg message handlers
//class CStudent
CTypedPtrList<CObList,CStudent*> lists;void CReg::New(CString * array)
{
CStudent *stu = new CStudent;
stu->ChangePrivate(array);
lists.AddTail(stu); //CStudent stu;
//stu.ChangePrivate(array);
//lists.AddTail(&stu);
}void CReg::OnOK()
{
// TODO: Add extra validation here
CString Private[6];
//char * Private[7]={"学号","姓名","性别","年龄","年级","密码","已选修学分数"};
m_num.GetWindowText(Private[0]);
m_name.GetWindowText(Private[1]);
m_sex.GetWindowText(Private[2]);
m_age.GetWindowText(Private[3]);
m_grade.GetWindowText(Private[4]);
m_password.GetWindowText(Private[5]); New(Private); CDialog::OnOK();
}BOOL CReg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_sex.AddString("男");
m_sex.AddString("女");
m_sex.SelectString(-1,"男");
m_ok.EnableWindow(FALSE); return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}void CReg::OnChangeEdit1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
CString temp[3];
m_name.GetWindowText(temp[0]);
m_num.GetWindowText(temp[1]);
m_password.GetWindowText(temp[2]);
if(temp[0]!="" && temp[1]!="" && temp[2]!="")
{
m_ok.EnableWindow(TRUE);
}
else
m_ok.EnableWindow(FALSE);
}void CReg::OnChangeEdit2()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
CString temp[3];
m_name.GetWindowText(temp[0]);
m_num.GetWindowText(temp[1]);
m_password.GetWindowText(temp[2]);
if(temp[0]!="" && temp[1]!="" && temp[2]!="")
{
m_ok.EnableWindow(TRUE);
}
else
m_ok.EnableWindow(FALSE);
}void CReg::OnChangeEdit3()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
CString temp[3];
m_name.GetWindowText(temp[0]);
m_num.GetWindowText(temp[1]);
m_password.GetWindowText(temp[2]);
if(temp[0]!="" && temp[1]!="" && temp[2]!="")
{
m_ok.EnableWindow(TRUE);
}
else
m_ok.EnableWindow(FALSE);
}