添加新类出现的有关问题!请高手解答
添加新类出现的问题!请高手解答!
我新建个MyHMMCWS项目
在 CMyHMMCWSDlg.h中 #include "myList.h "
出现如下编译错误!
myList.obj : error LNK2019: unresolved external symbol "public: __thiscall mynode::mynode(class ATL::CStringT <wchar_t,class StrTraitMFC_DLL <wchar_t,class ATL::ChTraitsCRT <wchar_t> > > ,double *,class mynode *) " (??0mynode@@QAE@V?$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@PANPAV0@@Z) referenced in function "public: int __thiscall myList::append(class ATL::CStringT <wchar_t,class StrTraitMFC_DLL <wchar_t,class ATL::ChTraitsCRT <wchar_t> > > ,double *) " (?append@myList@@QAEHV?$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@PAN@Z)
D:\VC work\MyHMMCWS\Debug\MyHMMCWS.exe : fatal error LNK1120: 1 unresolved externals
看不懂,MyHMMCWS项目仅仅添加了变量,
现在把myList类代码贴出来:
//-----------myList.h------------
#pragma once
class myList;
class mynode{
public:
friend class myList;
mynode(CString word,double *data,mynode *link); //构造函数
private:
CString word;
double *data;
mynode *link;
};
class myList
{
public:
myList(void);
int append(CString words,double *datas);
~myList(void);
private:
mynode *first,*last;
};
mynode::mynode(CString cword,double *cdata,mynode *clink)
{
this-> data=cdata;
this-> word=cword;
this-> link=NULL;
}
//--------------------------
//---------------myList.cpp-------
#include "StdAfx.h "
#include "myList.h "
myList::myList(void)
{
first=last=NULL;
}
int myList::append(CString words, double *datas)
{
mynode *newnode=new mynode(words,datas,NULL);
if(first=NULL)
{
first=last=newnode;
}
else {
last-> link=newnode;
last=newnode;
}
return 1;
}
myList::~myList(void)
{
}
//-------------
如果不include就能编译成功,请达人解释!!
------解决方案--------------------
myList.cpp文件有没有添加到项目中?或者说,实现错误中的那些符号的文件有没有编译连接?
------解决方案--------------------
我实验了一下你的代码,并没有发现问题哦。
跟你的似乎没有区别,我直接使用 insert 添加的新类 .h 文件
// myList.h: interface for the myList class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_MYLIST_H__2B0ED090_E1D2_43F7_84EF_E93529DFAFF5__INCLUDED_)
#define AFX_MYLIST_H__2B0ED090_E1D2_43F7_84EF_E93529DFAFF5__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class myList;
class mynode{
public:
friend class myList;
mynode(CString word,double *data,mynode *link); //¹¹Ô캯Êý
private:
CString word;
double *data;
mynode *link;
};
class myList
{
public:
myList(void);
int append(CString words,double *datas);
~myList(void);
我新建个MyHMMCWS项目
在 CMyHMMCWSDlg.h中 #include "myList.h "
出现如下编译错误!
myList.obj : error LNK2019: unresolved external symbol "public: __thiscall mynode::mynode(class ATL::CStringT <wchar_t,class StrTraitMFC_DLL <wchar_t,class ATL::ChTraitsCRT <wchar_t> > > ,double *,class mynode *) " (??0mynode@@QAE@V?$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@PANPAV0@@Z) referenced in function "public: int __thiscall myList::append(class ATL::CStringT <wchar_t,class StrTraitMFC_DLL <wchar_t,class ATL::ChTraitsCRT <wchar_t> > > ,double *) " (?append@myList@@QAEHV?$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@PAN@Z)
D:\VC work\MyHMMCWS\Debug\MyHMMCWS.exe : fatal error LNK1120: 1 unresolved externals
看不懂,MyHMMCWS项目仅仅添加了变量,
现在把myList类代码贴出来:
//-----------myList.h------------
#pragma once
class myList;
class mynode{
public:
friend class myList;
mynode(CString word,double *data,mynode *link); //构造函数
private:
CString word;
double *data;
mynode *link;
};
class myList
{
public:
myList(void);
int append(CString words,double *datas);
~myList(void);
private:
mynode *first,*last;
};
mynode::mynode(CString cword,double *cdata,mynode *clink)
{
this-> data=cdata;
this-> word=cword;
this-> link=NULL;
}
//--------------------------
//---------------myList.cpp-------
#include "StdAfx.h "
#include "myList.h "
myList::myList(void)
{
first=last=NULL;
}
int myList::append(CString words, double *datas)
{
mynode *newnode=new mynode(words,datas,NULL);
if(first=NULL)
{
first=last=newnode;
}
else {
last-> link=newnode;
last=newnode;
}
return 1;
}
myList::~myList(void)
{
}
//-------------
如果不include就能编译成功,请达人解释!!
------解决方案--------------------
myList.cpp文件有没有添加到项目中?或者说,实现错误中的那些符号的文件有没有编译连接?
------解决方案--------------------
我实验了一下你的代码,并没有发现问题哦。
跟你的似乎没有区别,我直接使用 insert 添加的新类 .h 文件
// myList.h: interface for the myList class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_MYLIST_H__2B0ED090_E1D2_43F7_84EF_E93529DFAFF5__INCLUDED_)
#define AFX_MYLIST_H__2B0ED090_E1D2_43F7_84EF_E93529DFAFF5__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class myList;
class mynode{
public:
friend class myList;
mynode(CString word,double *data,mynode *link); //¹¹Ô캯Êý
private:
CString word;
double *data;
mynode *link;
};
class myList
{
public:
myList(void);
int append(CString words,double *datas);
~myList(void);