提示 error LNK2001: 无法解析的外部符号 "class Linklist link" (?link@@3VLinklist@@
做链表作业,都写好了,结果运行的时候突然出来这么个提示,该怎么处理啊,代码上也没看出错误来啊,求大神啊!!!!程序代码:
struct node { CString num,name,photo; node *next; }; class Linklist { private: node *p; public: node *head; Linklist(); bool add(CString a,CString b); bool add(CString a,CString b,CString c); bool del(CString a); bool del(CString a,CString b); node* find(CString a); node* find(CString a,CString b); bool change(CString a,CString b,CString c); }; #include "stdafx.h" #include"linklist.h" Linklist::Linklist() { head=new node; head->next=NULL; } node* Linklist::find(CString a) { node *p; for(p=head->next;p!=NULL;p=p->next) { if(p->num==a) return p; } return p; } node* Linklist::find(CString a,CString b) { node *p; for(p=head->next;p!=NULL;p=p->next) { if(p->name==b) return p; } return p; } bool Linklist::add(CString a, CString b) { node *p=find(a); if(p!=NULL) return 0; else { node *q=new node; q->next=head->next; head->next=q; q->num=a; q->name=b; return 1; } } bool Linklist::add(CString a, CString b,CString c) { node *p=find(a); if(p!=NULL) return 0; else { node *q=new node; q->next=head->next; head->next=q; q->num=a; q->name=b; q->photo=c; return 1; } } bool Linklist::del(CString a) { node *p,*q; for(p=head->next,q=head;p!=NULL;p=p->next,q=q->next) { if(p->num==a) { q->next=p->next; delete p; return 1; } } return 0; } bool Linklist::del(CString a, CString b) { node *p,*q; for(p=head->next,q=head;p!=NULL;p=p->next,q=q->next) { if(p->name==b) { q->next=p->next;//MessageBox(NULL,_T("ok"),_T("ok"),MB_ICONWARNING); delete p; return 1; } } return 0; } bool Linklist::change(CString a, CString b, CString c) { node *p=find(a); if(p==NULL) return 0; else { p->num=a; p->name=b; p->photo=c; return 1; } } // bhtDlg.cpp : 实现文件 // #include "stdafx.h" #include "bht.h" #include "bhtDlg.h" #include "linklist.h" extern Linklist link; #ifdef _DEBUG #define new DEBUG_NEW #endif // 用于应用程序“关于”菜单项的CAboutDlg 对话框 class CAboutDlg : public CDialog { public: CAboutDlg(); // 对话框数据 enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 // 实现 protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) END_MESSAGE_MAP() // CbhtDlg 对话框 CbhtDlg::CbhtDlg(CWnd* pParent /*=NULL*/) : CDialog(CbhtDlg::IDD, pParent) , t_num(_T("")) , t_photo(_T("")) , t_name(_T("")) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CbhtDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Text(pDX, IDC_EDIT1, t_num); DDV_MaxChars(pDX, t_num, 100); DDX_Text(pDX, IDC_EDIT3, t_photo); DDX_Text(pDX, IDC_EDIT2, t_name); DDX_Control(pDX, IDC_LIST1, x_list); DDX_Control(pDX, IDC_photo, m_photo); } BEGIN_MESSAGE_MAP(CbhtDlg, CDialog) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_BN_CLICKED(IDC_BUTTON2, &CbhtDlg::OnBnClickedButton2) ON_BN_CLICKED(IDC_BUTTON3, &CbhtDlg::OnBnClickedButton3) ON_BN_CLICKED(IDC_BUTTON4, &CbhtDlg::OnBnClickedButton4) ON_BN_CLICKED(IDC_BUTTON5, &CbhtDlg::OnBnClickedButton5) ON_BN_CLICKED(IDC_BUTTON1, &CbhtDlg::OnBnClickedButton1) END_MESSAGE_MAP() // CbhtDlg 消息处理程序 BOOL CbhtDlg::OnInitDialog() { CDialog::OnInitDialog(); // 将“关于...”菜单项添加到系统菜单中。 DWORD dwStyle = x_list.GetExtendedStyle(); dwStyle |= LVS_EX_FULLROWSELECT;//选中某行使整行高亮(只适用与report风格的listctrl) dwStyle |= LVS_EX_GRIDLINES;//网格线(只适用与report风格的listctrl) x_list.SetExtendedStyle(dwStyle); //设置扩展风格 x_list.InsertColumn(0,"学号",LVCFMT_LEFT,95,0); x_list.InsertColumn(1,"姓名",LVCFMT_LEFT,85,1); // IDM_ABOUTBOX 必须在系统命令范围内。 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动 // 执行此操作 SetIcon(m_hIcon, TRUE); // 设置大图标 SetIcon(m_hIcon, FALSE); // 设置小图标 // TODO: 在此添加额外的初始化代码 return TRUE; // 除非将焦点设置到控件,否则返回TRUE } void CbhtDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // 如果向对话框添加最小化按钮,则需要下面的代码 // 来绘制该图标。对于使用文档/视图模型的MFC 应用程序, // 这将由框架自动完成。 void CbhtDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // 用于绘制的设备上下文 SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0); // 使图标在工作区矩形中居中 int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // 绘制图标 dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } //当用户拖动最小化窗口时系统调用此函数取得光标 //显示。 HCURSOR CbhtDlg::OnQueryDragIcon() { return static_cast<HCURSOR>(m_hIcon); } void CbhtDlg::OnBnClickedButton2() { // TODO: 在此添加控件通知处理程序代码' UpdateData(true); if(t_num.IsEmpty()) MessageBox("学号不能为空","错误",MB_ICONWARNING); else if(t_name.IsEmpty()) MessageBox("姓名不能为空","错误",MB_ICONWARNING); else if(t_photo.IsEmpty()) { if(link.add(t_num,t_name)) { x_list.InsertItem(0,t_num); x_list.SetItemText(0,1,t_name); } else MessageBox("该数据已存在","错误",MB_ICONWARNING); } else { if(link.add(t_num,t_name,t_photo)) { x_list.InsertItem(0,t_num); x_list.SetItemText(0,1,t_name); } else MessageBox("该数据已存在","错误",MB_ICONWARNING); } UpdateData(false); } void CbhtDlg::OnBnClickedButton3() { // TODO: 在此添加控件通知处理程序代码 UpdateData(true); if(t_num.IsEmpty()) MessageBox("学号不能为空","错误",MB_ICONWARNING); else if(t_name.IsEmpty()) MessageBox("姓名不能为空","错误",MB_ICONWARNING); else { if(link.del(t_num,t_name)) { MessageBox("删除成功"); for(int i=0;;i++) if(x_list.GetItemText(i,0)==t_num) {x_list.DeleteItem(i);break;} } else MessageBox("该数据不存在","错误",MB_ICONWARNING); } UpdateData(false); } void CbhtDlg::OnBnClickedButton4() { // TODO: 在此添加控件通知处理程序代码 UpdateData(true); node *p; if(!t_num.IsEmpty()) p=link.find(t_num); else if(!t_name.IsEmpty()) p=link.find(t_num,t_name); else {MessageBox("学号和姓名不能全为空","提示");return;} if(p==NULL) MessageBox("没有找到该数据","提示"); else { t_num=p->num;t_name=p->name;t_photo=p->photo; if(!t_photo.IsEmpty()) photo_show(); } UpdateData(false); } void CbhtDlg::OnBnClickedButton5() { // TODO: 在此添加控件通知处理程序代码 UpdateData(true); if(!t_name.IsEmpty()&&!t_num.IsEmpty()) { if(link.change(t_num,t_name,t_photo)) { MessageBox("修改成功","提示"); for(int i=0;;i++) if(x_list.GetItemText(i,0)==t_num) { x_list.SetItemText(i,0,t_num); x_list.SetItemText(i,1,t_name); break; } if(!t_photo.IsEmpty()) photo_show(); } else MessageBox("该学号不存在","错误"); } else {MessageBox("学号或姓名不能为空","提示");return;} UpdateData(false); } void CbhtDlg::OnBnClickedButton1() { // TODO: 在此添加控件通知处理程序代码 UpdateData(true); CFileDialog m_file(true,"bmp",NULL,NULL,"位图文件(.bmp)|*.bmp",this); if(m_file.DoModal()==IDOK) { CString pathname=m_file.GetPathName(); t_photo=pathname; } photo_show(); UpdateData(false); } void CbhtDlg::photo_show() { HBITMAP hbitmap=(HBITMAP)::LoadImage(AfxGetInstanceHandle(),t_photo,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_DEFAULTCOLOR|LR_DEFAULTSIZE); m_photo.SetBitmap(hbitmap); /*CRect rect,imageRect; m_photo.GetWindowRect(imageRect); this->GetWindowRect(rect); rect.right=imageRect.right+20; rect.bottom=imageRect.bottom+20; this->MoveWindow(rect);*/ }