When I was playing around a few days ago with the contest att cpphome I discovered a strange thing in CodeWarrior.
This code actually compiles!
There's one ) too much on the red line but the code still compiles!Code:template <int n1, int d1, int n2, int d2> struct add_fraction { static const int numerator; static const int denominator; }; int gcd(int a,int b) { if (a==b) return a; if (a>b) return gcd(a-b,b); return gcd(b-a,a); } template <int n1, int d1, int n2, int d2> const int add_fraction<n1,d1,n2,d2>::numerator = (n1*d2+n2*d1)/gcd(n1*d2+n2*d1,d1*d2)); //One ) too much template <int n1, int d1, int n2, int d2> const int add_fraction<n1,d1,n2,d2>::denominator = (d1*d2)/gcd(n1*d2+n2*d1,d1*d2);
Note that I found a much better solution to the contest problem later, but I am quite amazed that this code is accepted!



LinkBack URL
About LinkBacks




)</edit>