STL map 报错:error C2143: syntax error : missing ';' before '<'
#ifndef __P35_H__
#define __P35_H__
#include <IOSTREAM>
#include <MAP>
#include <algorithm>
struct CidToId
{
int cid;
int cmt;//cid make time
};
CidToId cidtoid;
typedef map <int, cidtoid> Map_CidToServerId;
typedef map <int, Map_CidToServerId> Map_TidToCid;
Map_TidToCid map_tidtocid;
Map_TidToCid::iterator it_tidtocid;
Map_CidToServerId::iterator it_cidtoserverid;
InsertTid(int tid, int cid);
#endif
e:\my file\hello world\p35\p35.h(16) : error C2143: syntax error : missing ';' before '<'
e:\my file\hello world\p35\p35.h(16) : error C2143: syntax error : missing ';' before '<'
e:\my file\hello world\p35\p35.h(17) : warning C4091: 'typedef ' : ignored on left of 'int' when no variable is declared
e:\my file\hello world\p35\p35.h(17) : error C2143: syntax error : missing ';' before '<'
e:\my file\hello world\p35\p35.h(17) : error C2143: syntax error : missing ';' before '<'
e:\my file\hello world\p35\p35.h(19) : error C2146: syntax error : missing ';' before identifier 'map_tidtocid'
e:\my file\hello world\p35\p35.h(19) : error C2501: 'Map_TidToCid' : missing storage-class or type specifiers
e:\my file\hello world\p35\p35.h(19) : fatal error C1004: unexpected end of file found
一下的.cpp供大家参考:
InsertTid(int tid, int cid, int sip)stl map algorithm struct c
{
int i = 0;
if(map_tidtocid.end() == (it_tidtocid = map_tidtocid.find(tid)))//tid find fail
{
map_tidtocid[tid];//insert tid
it_tidtocid = map_tidtocid.find(tid);//iterator
}
if(it_tidtocid->second.end() == (it_cidtoserverid = it_tidtocid->second.find(sip)))//find cid fail
{
it_tidtocid->second[sip];//insert cid
it_cidtoserverid = it_tidtocid->second.find(sip);
it_cidtoserverid->second.cid = cid;
it_cidtoserverid->second.cmt = (int)time(NULL);
}
else
{
it_cidtoserverid->second.cid = cid;
it_cidtoserverid->second.cmt = (int)time(NULL);
}
}
[解决办法]
typedef map <int, Cidtoid> Map_CidToServerId;
[解决办法]
typedef?map?<int,?cidtoid>?Map_CidToServerId;
[解决办法]
CidToId cidtoid;
typedef map <int, cidtoid> Map_CidToServerId;
map<int,CidToId> -->map<T1,T2> 是类型,你直接用对象...
[解决办法]
#ifndef __P35_H__
#define __P35_H__
//#include <IOSTREAM>
//#include <MAP>
#include <iostream>
#include <map>
#include <algorithm>
using std::map;
.....
[解决办法]
InsertTid(int tid, int cid); 这是函数? 咋没返回类型
[解决办法]
#ifndef __P35_H__
#define __P35_H__
#include <IOSTREAM>
#include <MAP>
#include <algorithm>
struct CidToId
{
int cid;
int cmt;//cid make time
};
CidToId cidtoid;
typedef map <int, CidToId> Map_CidToServerId;
typedef map <int, Map_CidToServerId> Map_TidToCid;
Map_TidToCid map_tidtocid;
Map_TidToCid::iterator it_tidtocid;
Map_CidToServerId::iterator it_cidtoserverid;
void InsertTid(int tid, int cid);
#endif
void InsertTid(int tid, int cid, int sip)
{
int i = 0;
if(map_tidtocid.end() == (it_tidtocid = map_tidtocid.find(tid)))//tid find fail
{
map_tidtocid[tid];//insert tid
it_tidtocid = map_tidtocid.find(tid);//iterator
}
if(it_tidtocid->second.end() == (it_cidtoserverid = it_tidtocid->second.find(sip)))//find cid fail
{
it_tidtocid->second[sip];//insert cid
it_cidtoserverid = it_tidtocid->second.find(sip);
it_cidtoserverid->second.cid = cid;
it_cidtoserverid->second.cmt = (int)time(NULL);
}
else
{
it_cidtoserverid->second.cid = cid;
it_cidtoserverid->second.cmt = (int)time(NULL);
}
return;
}
[解决办法]
你那代码编译的时候
1>e:\demo\demo\stdafx.h(103): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>e:\demo\demo\stdafx.h(107): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>e:\demo\demo\stdafx.h(126): warning C4508: 'InsertTid' : function should return a value; 'void' return type assumed
报错直接就找到 没返回类型啊
[解决办法]
加上名字空间
//typedef map <int, int> Map_CidToServerId;
typedef std::map <int, int> Map_CidToServerId;
[解决办法]
.......难道你们都没看出来是没有加using std::map吗?
改成这样,应该就ok了:
typedef std::map <int, CidToId> Map_CidToServerId;