64,649
社区成员
发帖
与我相关
我的任务
分享
#include <string>
#include <vector>
#include <algorithm>
using std::string;
using std::vector;
typedef struct tagNode
{
tagNode()
{
}
tagNode(string a,int b)
{
this->a = a;
this->b = b;
}
bool operator ==(const tagNode& node)
{
return (this->a == node.a && this->b == node.b);
}
//感觉这边不太妥,该如何改呢?
bool operator ==(const tagNode* const node)
{
return (this->a == node->a && this->b == node->b);
}
string a;
int b;
}Node,*pNode;
int main(int argc, char* argv[])
{
Node node1("hello",0);
Node node2("hello",0);
pNode pnode1 = new Node("hello",0);
pNode pnode2 = new Node("hello",0);
//起作用了,调用了bool operator ==(const tagNode& node)
if(node1==node2)
printf("Node:equal\n");
//不起作用,未调用bool operator ==(const tagNode* const node)
if(pnode1==pnode2)
printf("pNode:equal\n");
delete pnode1;
delete pnode2;
getchar();
return 0;
}
template<class InputIterator, class T>
InputIterator find ( InputIterator first, InputIterator last, const T& value )
{
for ( ;first!=last; first++) if ( *first==value ) break;
return first;
}
bool operator ==(const tagNode* const node)
{
return (this->a == node->a && this->b == node->b);
}
bool operator==(const pNode n1, const pNode n2)
{
return (*n1 == *n2);
}
node.cpp:45: error: ‘bool operator==(tagNode*, tagNode*)’ must have an argument of class or enumerated type
if( *pnode1 == *pnode2)
printf("pNode:equal\n");
bool operator ==(const tagNode & node)
{
return (this->a == node.a && this->b == node.b);
}
bool operator ==(const tagNode* const node)
{
return (this->a == node->a && this->b == node->b);
}
bool operator==(const pNode n1, const pNode n2)
{
return (*n1 == *n2);
}
node.cpp:45: error: ‘bool operator==(tagNode*, tagNode*)’ must have an argument of class or enumerated type
if( *pnode1 == *pnode2)
printf("pNode:equal\n");
bool operator ==(const tagNode & node)
{
return (this->a == node.a && this->b == node.b);
}