L
Lars Tackmann
Hi i have a struct defined - and would like to define the usual comparison
opaerators on it (<=, == ...). My struct look like this:
--------------------------------------------------------------
typedef struct Node{
double value; // value of node
char *name; // name of node
// define I/O on nodes
friend ostream &operator<<(ostream &out, const Node &n){
out << n.name << " " << n.value;
return out;
}
friend istream &operator>>(istream &in, Node &n){
in >> n.name >> n.value;
return in;
}
// define comparison operators on nodes
bool operator<(const Node &rNode, const Node &lNode){
return bool(rNode.value < lNode.value);
}
} Node;
------------------------------------------------------------------
if i try to compile this code(with g++ 3.2.2) i get
------------------------------------------------------------------
bool Node:perator<(const Node&, const Node&)' must take exactly
one argument
------------------------------------------------------------------
Which does seam a bit odd because the < operator is infix and takes two
arguments. So my question is how do i implment my struct i norder to be
able to define comparison on it ????.
Thanks
opaerators on it (<=, == ...). My struct look like this:
--------------------------------------------------------------
typedef struct Node{
double value; // value of node
char *name; // name of node
// define I/O on nodes
friend ostream &operator<<(ostream &out, const Node &n){
out << n.name << " " << n.value;
return out;
}
friend istream &operator>>(istream &in, Node &n){
in >> n.name >> n.value;
return in;
}
// define comparison operators on nodes
bool operator<(const Node &rNode, const Node &lNode){
return bool(rNode.value < lNode.value);
}
} Node;
------------------------------------------------------------------
if i try to compile this code(with g++ 3.2.2) i get
------------------------------------------------------------------
bool Node:perator<(const Node&, const Node&)' must take exactly
one argument
------------------------------------------------------------------
Which does seam a bit odd because the < operator is infix and takes two
arguments. So my question is how do i implment my struct i norder to be
able to define comparison on it ????.
Thanks