#includ<list>//infoB信息结构
typedef struct infoB
{
char Name[64];
list<timeval> timeList;时间链表头
}; //infoA信息结构
typedef struct infoA
{
char name[16];
list<infoB > infoBList;//infoB信息列表头
};
infoA * g_info = NULL;//全局的指针,将做为头结点,把N个infoA插入到g_info中;(想用g_info存信息)
infoA中有2个成员,其中infoBList存放的是M个infoB的结构,其中infoB又有一个成员和一个存放timeval类型的时间表;请问我这种用法对吗? 单独编译通过,一旦整个代码编译就出现如下:
: error LNK2019: 无法解析的外部符号 "public: static void __cdecl stlp_priv::_List_global<bool>::_Transfer(struct stlp_priv::_List_node_base *,struct stlp_priv::_List_node_base *,struct stlp_priv::_List_node_base *)" (?_Transfer@?$_List_global@_N@stlp_priv@@SAXPAU_List_node_base@2@00@Z),该符号在函数 "public: void __thiscall stlp_priv::_Impl_list<struct timeval,class stlp_std::allocator<struct timeval> >::splice(struct stlp_priv::_List_iterator<struct timeval,struct stlp_std::_Nonconst_traits<struct timeval> >,class stlp_priv::_Impl_list<struct timeval,class stlp_std::allocator<struct timeval> > &)" (?splice@?$_Impl_list@Utimeval@@V?$allocator@Utimeval@@@stlp_std@@@stlp_priv@@QAEXU?$_List_iterator@Utimeval@@U?$_Nonconst_traits@Utimeval@@@stlp_std@@@2@AAV12@@Z) 中被引用
fatal error LNK1120: 1 个无法解析的外部命令
类似下面这样就出错:
void FindList(infoA *pA,infoB *pB)
{
list<infoB >::iterator iter;
for (iter = pA->infoBList.begin(); iter != pA->infoBList.end(); iter++)
{
*pB= *iter;//这句注释掉就不出错,
}
}
typedef struct infoB
{
char Name[64];
list<timeval> timeList;时间链表头
}; //infoA信息结构
typedef struct infoA
{
char name[16];
list<infoB > infoBList;//infoB信息列表头
};
infoA * g_info = NULL;//全局的指针,将做为头结点,把N个infoA插入到g_info中;(想用g_info存信息)
infoA中有2个成员,其中infoBList存放的是M个infoB的结构,其中infoB又有一个成员和一个存放timeval类型的时间表;请问我这种用法对吗? 单独编译通过,一旦整个代码编译就出现如下:
: error LNK2019: 无法解析的外部符号 "public: static void __cdecl stlp_priv::_List_global<bool>::_Transfer(struct stlp_priv::_List_node_base *,struct stlp_priv::_List_node_base *,struct stlp_priv::_List_node_base *)" (?_Transfer@?$_List_global@_N@stlp_priv@@SAXPAU_List_node_base@2@00@Z),该符号在函数 "public: void __thiscall stlp_priv::_Impl_list<struct timeval,class stlp_std::allocator<struct timeval> >::splice(struct stlp_priv::_List_iterator<struct timeval,struct stlp_std::_Nonconst_traits<struct timeval> >,class stlp_priv::_Impl_list<struct timeval,class stlp_std::allocator<struct timeval> > &)" (?splice@?$_Impl_list@Utimeval@@V?$allocator@Utimeval@@@stlp_std@@@stlp_priv@@QAEXU?$_List_iterator@Utimeval@@U?$_Nonconst_traits@Utimeval@@@stlp_std@@@2@AAV12@@Z) 中被引用
fatal error LNK1120: 1 个无法解析的外部命令
类似下面这样就出错:
void FindList(infoA *pA,infoB *pB)
{
list<infoB >::iterator iter;
for (iter = pA->infoBList.begin(); iter != pA->infoBList.end(); iter++)
{
*pB= *iter;//这句注释掉就不出错,
}
}
去掉typedef就可以了
按楼主给出的部分代码,我自己写了一份接近的,运行正常,VC6.0下,STL也是VC6.0自带版本。
至少可以说明楼主的用法应该是可行的。#include <list>
#include <iostream>
using namespace std;
//infoB信息结构
typedef struct infoB
{
char Name[64];
list<int> timeList;//时间链表头
};//infoA信息结构
typedef struct infoA
{
char name[16];
list <infoB > infoBList;//infoB信息列表头
}; void FindList(infoA *pA,infoB *pB)
{
list <infoB >::iterator iter;for (iter = pA->infoBList.begin(); iter != pA->infoBList.end(); iter++)
{
if (strcmp((*iter).Name, pB->Name) == 0)
{
*pB = *iter; //这句注释掉就不出错,
}
}
} infoA * g_info = NULL;
int main()
{
g_info = new infoA();
strcpy(g_info->name, "helllo");
infoB ib, ib2, ib3;
strcpy(ib.Name, "infoB1");
ib.timeList.push_back(123);
ib.timeList.push_back(121);
strcpy(ib2.Name, "infoB2");
ib2.timeList.push_back(223);
ib2.timeList.push_back(221); strcpy(ib3.Name, "infoB3");
ib3.timeList.push_back(323);
ib3.timeList.push_back(321); g_info->infoBList.push_back(ib);
g_info->infoBList.push_back(ib2);
g_info->infoBList.push_back(ib3); infoB findB;
strcpy(findB.Name, "infoB2");
FindList(g_info, &findB);
for (list<int>::iterator ii=findB.timeList.begin(); ii!=findB.timeList.end(); ii++)
{
cout << *ii << "\t";
}
cout << endl;
delete g_info;
}
struct infoB
{
char Name[64];
list <timeval> timeList;时间链表头
};
别这么干,
一个结构,下面这样写可以吧,
infoB a = { 0 };
但是这样,timeList 肯定出错,所以最好把 infoB 写成类,这样 timeList 才有机会初始化,