C_and_CPP 板


LINE

不好意思,结构上有点复杂,就像前几天说的那个,类似资料库的结构 class TP_Gra{ public: TP_Gra(int vID,Point vOrigin_Position); TP_Gra(); ~TP_Gra(); void Set_ID(int vID){ID=vID;} int Get_ID(){return ID;} void Set_Coodinate(Point Position); Point Get_Coodinate(){return Origin_Position;} private: int ID; Point Origin_Position; }; class Truckload_TP_Gra{ typedef list<TP_Gra> Contents; public: Truckload_TP_Gra(); Truckload_TP_Gra(TP_Gra one_TP); void add_TP(TP_Gra new_TP); int Get_First_Ob_ID(); int Get_Last_Ob_ID(); Point Get_First_Ob_Coodinate(); Point Get_Last_Ob_Coodinate(); TP_Gra Get_Now_OB(int vID); //仿函式 class Find_Ob_by_ID{ public: Find_Ob_by_ID (int val):_value(val){} bool operator()(TP_Gra& lhs){ return (lhs.Get_ID() == _value);} private: int _value; }; private: Contents Load; }; class Token_Place_Output{ typedef vector<_Point> Pos; public: void Set_TP_ID(int vID); int Get_TP_ID(); void Set_TP_Con_Trans_ID(int vID); int Get_TP_Con_Trans_ID(); void Set_Mid_Point(_Point P); void Set_Arc_Type(int type); int Get_Arc_Type(); void Clear(); private: int TP_ID; int Transition_ID; Pos Mid_Point; int Arc_Type; }; class Truckload_Con_TP_Out{ typedef list<Token_Place_Output> Contents; public: Truckload_Con_TP_Out(); Truckload_Con_TP_Out(Token_Place_Output one_Row); void add_Con_Data(Token_Place_Output new_Row); Token_Place_Output Get_Now_OB(int vTP_ID,int vTransition_ID); Token_Place_Output Get_First_OB(); Token_Place_Output Get_End_OB(); int Get_Count(); // 仿函式 class Find_Ob_by_ID{ public: Find_Ob_by_ID (int vTP_ID,int vTransition_ID):TP_ID(vTP_ID), Transition_ID(vTransition_ID) {} bool operator()(Token_Place_Output& lhs){ return (lhs.Get_TP_ID() == TP_ID) && (lhs.Get_TP_Con_Trans_ID()==Transition_ID); } private: int TP_ID; int Transition_ID; }; private: Contents Load; }; 然後我在主程式(在windows form上面)宣告了 Truckload_Con_TP_Out TPOut; ... 然後在某个事件中打了 for (list<Token_Place_Output>::iterator i=TPOut.Get_First_OB(); i=TPOut.Get_End_OB();i++){} (这只是个测试而已) 然後会有这样的错误 error C2440: '正在初始化' : 无法由 'Token_Place_Output' 转换为 'std::list<_Ty>::_Iterator<_Secure_validation>' error C2679: 二元运算子 '=' : 找不到使用右方运算元型别 'Token_Place_Output' 的运算子 (或是没有可接受的转换) 变数i的宣告出了问题,但我不知道错在哪,麻烦有经验的大大回答一下,谢谢 Token_Place_Output Truckload_Con_TP_Out::Get_First_OB(){ return *(Load.begin());} (是因为这个定义才错的吗??) --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 163.18.48.28 ※ 编辑: tyc5116 来自: 163.18.48.28 (07/20 22:53) ※ 编辑: tyc5116 来自: 163.18.48.28 (07/20 23:10)
1F:推 legnaleurc:你不需要加 * 07/20 23:17
不加的话 error C2664: 'Token_Place_Output::Token_Place_Output(const Token_Place_Output &)' : 无法将参数 1 从 'std::list<_Ty>::_Iterator<_Secure_validation>' 转换成 'const Token_Place_Output &' ※ 编辑: tyc5116 来自: 163.18.48.28 (07/20 23:19)
2F:→ tyc5116:好像它会自己产生复制建构函式,是吗? 07/20 23:24
3F:→ akasan:TPOut.Get_*传回TPOut.Get_First_OB 07/20 23:52
4F:→ akasan:你却用list<Token_Place_Output>::iterator接 07/20 23:52
5F:→ akasan:当然会错,一楼所说的方向倾向於将TPOut.Get_*系列 07/20 23:53
6F:→ akasan:改成回传list<Token_Place_Output>::iterator 07/20 23:53
7F:→ akasan:个人也比较建议改TPOut.Get_*系列的回传型别 07/20 23:54
8F:→ tyc5116:不是很懂...可以在错的地方改一下,然後再配合解释吗,谢谢 07/21 00:04
9F:→ miecowbai:你的i定义为iterator,而等於的右边却是 07/21 00:47
10F:→ miecowbai:Token_Place_Output, 所以才会错 07/21 00:48
11F:→ tyc5116:喔...这样说我就懂了,但是先有一个大大跟我说iterator不要 07/21 01:03
12F:→ tyc5116:暴露在外面,但我目前想到的就是在类别中,加一个函式 07/21 01:03
13F:→ tyc5116:就像#1ALkPB_3的那种方式,但是这样就暴露出来了 07/21 01:06
14F:→ tyc5116:还有其它的写法吗 07/21 01:06
15F:→ tyc5116:唔....我好像想通了...谢谢上面的各位...^^ 07/21 01:11
16F:→ tyc5116:我再去试试 07/21 01:11







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:e-shopping站内搜寻

TOP