1: note of learning stl c++
来源:互联网 发布:服务器ftp软件 编辑:程序博客网 时间:2024/05/16 00:55
Code reuse is the STL'S soul------------------my first expression to stl .May be it just a foo's think.
my first program ::the list opration of insert ,remove : :element is struct node :
First remember :if you typedef a new data struct when you use the list or queue or other container ,you must overload the operation ==
such as my program like this the list element is struct Node ,when we remove a element from a list ,if you use the function of find ,remove be remember overload the operation == and the parameter of this overload function must be const.when you in linux the g++ complier will be note you the candicate of ==is
bool operator ==(TP_ & v)
but in windows it will be note that
bool operator ==(const TP_ & v)
so from the two note ,through my erperiment the linux's is a error note ,just to say the TP_ must be a const
variable.
the following code source cmplie success on o/s linux enterprise AS4.0
test.cpp
#include <list>
#include <iostream>
#include <algorithm>
#include "aa.h"
using namespace std;
bool Node::operator==(const Node&a)
{
return ((p==a.p)&&(t==a.t));
}
int main()
{
list <Node> NodeList;
Node a,b,c,d;
a.p=1;
a.t=2;
b.p=3;
b.t=4;
c.p=5;
c.t=6;
d.p=7;
d.t=8;
NodeList.push_back(a);
NodeList.push_back(b);
NodeList.push_back(c);
NodeList.push_back(d);
list<Node>::iterator ListIterator;
for(ListIterator=NodeList.begin();ListIterator!=NodeList.end();ListIterator++)
cout<<(*ListIterator).p<<"---------"<<(*ListIterator).t<<endl;
//find(NodeList.begin(),NodeList.end(),a);
cout<<"------------------------------"<<endl;
NodeList.remove(b);
for(ListIterator=NodeList.begin();ListIterator!=NodeList.end();ListIterator++)
cout<<(*ListIterator).p<<"---------"<<(*ListIterator).t<<endl;
return 0;
}
=------------------------------=
aa.h
class Node
{
public:
int p;
int t;
bool operator==( const Node&a);
};
my first program ::the list opration of insert ,remove : :element is struct node :
First remember :if you typedef a new data struct when you use the list or queue or other container ,you must overload the operation ==
such as my program like this the list element is struct Node ,when we remove a element from a list ,if you use the function of find ,remove be remember overload the operation == and the parameter of this overload function must be const.when you in linux the g++ complier will be note you the candicate of ==is
bool operator ==(TP_ & v)
but in windows it will be note that
bool operator ==(const TP_ & v)
so from the two note ,through my erperiment the linux's is a error note ,just to say the TP_ must be a const
variable.
the following code source cmplie success on o/s linux enterprise AS4.0
test.cpp
#include <list>
#include <iostream>
#include <algorithm>
#include "aa.h"
using namespace std;
bool Node::operator==(const Node&a)
{
return ((p==a.p)&&(t==a.t));
}
int main()
{
list <Node> NodeList;
Node a,b,c,d;
a.p=1;
a.t=2;
b.p=3;
b.t=4;
c.p=5;
c.t=6;
d.p=7;
d.t=8;
NodeList.push_back(a);
NodeList.push_back(b);
NodeList.push_back(c);
NodeList.push_back(d);
list<Node>::iterator ListIterator;
for(ListIterator=NodeList.begin();ListIterator!=NodeList.end();ListIterator++)
cout<<(*ListIterator).p<<"---------"<<(*ListIterator).t<<endl;
//find(NodeList.begin(),NodeList.end(),a);
cout<<"------------------------------"<<endl;
NodeList.remove(b);
for(ListIterator=NodeList.begin();ListIterator!=NodeList.end();ListIterator++)
cout<<(*ListIterator).p<<"---------"<<(*ListIterator).t<<endl;
return 0;
}
=------------------------------=
aa.h
class Node
{
public:
int p;
int t;
bool operator==( const Node&a);
};
- 1: note of learning stl c++
- The NOTE of learning ASP.NET [1]
- The NOTE of learning ASP.NET [4]
- deeplearning Note : Practical aspects of Deep Learning
- Windows Azure Learning Note (1)
- Machine Learning week 1 note
- Chapter8. Objective-C learning note 1.
- c-learning-note(2017-9-20)
- c-learning-note(2017-9-21)
- c-learning-note(2017-9-22)
- Learning a Part of C++(for ACM/ICPC) (5) STL概览
- Learning a Part of C++(for ACM/ICPC) (6) STL算法
- Learning a Part of C++(for ACM/ICPC) (7) STL中的string和bitset
- Spring v3.0.2 Learning Note 3 - Initialisation of Beans
- Spring v3.0.2 Learning Note 4 - Scope of Beans
- Spring v3.0.2 Learning Note 5 - Lifecycle of Beans
- Note of learning Inside the Java Virtual Machine Chapter Five
- CalTech machine learning, video 6 note,theory of generalization
- 这几天研究了下 Google Sitemap 的实现
- eclipse下的struts资源文件中文问题
- Virginie Ruiz
- 你的身份不再是谜
- Xdoclet2(一):找回Doclipse缺失的标签提示--Qtags
- 1: note of learning stl c++
- 你掌握调试工具了吗?
- 从鼠标中获得输入--消息框
- 网络老婆与现实女友的对话 ---很好看
- 一个常见数据库操作错误的分析(四)
- 老婆的日记(爆笑)(看了你就想结婚了)
- 2005年中国科技十大骗局之一
- websphere 和 weblogic 在iframe使用上的一点不同
- 2005年中国科技十大骗局之二