'typedef ' : ignored on left of 'class CStringList' when no variable is declared

'typedef ' : ignored on left of 'class CStringList' when no variable is declared

问题描述:

//CListTest.cpp:Define the entry point for the console application
//#include"stdafx.h"
#include
#include
#include

using namespace std;

typedef CStringListStringList;
//实现一个以String为元素的数组类
//入参和出参都是一个指向string的指针
int main()//(int argc,_TCHAR* argv[])
{
const CString str[]={
_T("1st Score"),
_T("2nd Score"),
_T("3rd Score"),
_T("4th Score"),
};
CStringList list1;
size_t i=0;
//从链表头部向链表中添加记录
for(i=0;i<sizeof(str)/sizeof(CString);i++)
{
list1.AddHead(str[i]);
}

CString string;
while(!list1.IsEmpty())
{
string=list1.RemoveHead();
wcout<<LPCTSTR(string)<<endl;
//最好每次清空string
string.ReleaseBuffer();
}
cout<<endl;
return 0;
}
//程序代码如上,本来预计应输出:
/*4th Score
3rd Score
2nd Score
1st Score*/
// 但却显示错误为:
//D:\Visual C++ Project\CList_P96\CList.cpp(9) : warning C4091: 'typedef ' : ignored on left of 'class CStringList' when no variable is declared
//D:\Visual C++ Project\CList_P96\CList.cpp(9) : error C2143: syntax error : missing ';' before '<'
//D:\Visual C++ Project\CList_P96\CList.cpp(9) : error C2143: syntax error : missing ';' before '<'

你是不是没有添加对mfc的支持

我这里编译正常(唯一的修改typedef CStringList StringList;少空格,不知道是你没有写还是csdn的bug)

图片说明

还有,下次贴代码,请使用编辑器上</>的按钮格式化下,你这么贴代码不完整你没有发现么?

问题如果解决,请点我回答右边的采纳,谢谢

您所说的对MFC支持是怎么添加呢?我用的VC++6.0,直接创建的源程序然后编译的,没有添加MFC支持。(编程小白)还请指教