Hello! I am new in c++ and i want some help. I want to learn how to make a constructor with object arguments. I give my source code and I want to tell me if I am right or wrong and why. Here's the code:
#include <iostream>
#include <string>
using namespace std;
class mydate
{
private:
string day,time;
public:
mydate(string a = "NO DAY",string b = "NO TIME")
{
day = a;
time = b;}
You can only supply default arguments to the end of a function's parameter list.
1 2 3 4 5 6 7 8 9
//example, as to why this is...
void f(int x, int y = 0); //fine
void f(int x = 0, int y); //nope, but why?
int main() {
f(5); //Whoops! Which one whould it call? Is x = 5 and y = 0, or is y = 5 and x = 0
...
}
I know this doesn't apply when the data types are different*, but it's the rule.