1) There isn't a built-in equality for user classes but you can define an operator== function that lets you use the same syntax as for built in types:
class int2{public: int2(int a=0,int b=0) : x(a),y(b) { } bool operator==(const int2 &i) const { return(x==i.x && y==i.y); } int x,y;};
Note the use of const both for the parameter and for the method itself. These allow you to use this in more flexible situations.
void f(){ int2 a(1,2),b(3,4); if(a==b) blah; if(a==int2(10,20)) blah;}
2) No. Only the rightmost parameters can be defaulted in C++. You can, however, create muliple overloads of a function that will do what you want, provided the paramters are of different types:
void f(int a=10,const std::string &s="default"){ std::cout << a << " " << s << std::endl;}void f(const std::string &s){ f(10,s);}void x(){ f(); // prints "10 default" f(18); // prints "18 default" f("hello"); prints "10 hello" f(26,"arglebargle"); // prints "26 arglebargle"}
Not a perfect solution to your problem, but gets around a lot of situations.
[Edited by - EasilyConfused on December 13, 2006 10:59:29 AM]