In deplorable style, this program attempts to use constructors to add 3 numbers and print the results but sadly nothing gets printed. Can you spot the flaw?
#include <iostream>
int sum = 0;
class Add
{
public:
Add( int a, int b, int c ) { sum += a; Add x(b,c); }
Add( int a, int b ) { sum += a; Add x(b); }
Add( int a ) { sum += a; Add x(); }
Add( ) { std::cout << sum; sum = 0; }
};
int main()
{
Add x( 21, 15, 9 );
return 0;
}
To solve this problem, you can get help from static code analysis with PC-Lint Plus.
Just copy the code and try ist out in the free online demo:
Feel free to leave a comment about your solution.