Remember that the default values should be passed to the function as last few parameters.
#include <iostream>
using namespace std;
class Test {
public:
double getInterest(int principal, int year, double rate = 5.5) {
return principal * year * rate / 100;
}
};
int main() {
Test t;
cout << t.getInterest(1000, 2, 10) << endl;
cout << t.getInterest(1000, 2) << endl;
return 0;
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.