I started learning C++ and now I am lost, I don't see the logic in this. simply does not make sense to me how it is possible that I can add arguments to an object and then those arguments are used by the program. Sure I can memorize this feature, but can someone please explain the logic behind this? Everything else in C++ makes sense, I guess this probably does too, only I don't see it.
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
class Person{
private:
string name;
int age;
public:
Person(){
name = "undefined";
age = 0;
};
Person(string newname){
name = newname;
age = 0;
};
Person(string newname, int newage){
name = newname;
age = newage;
};
string toString(){
stringstream ss;
ss << "Name is: " << name << " Age is : " << age;
return ss.str();
};
};
int main()
{
Person person1;
Person person2("David"); // I don't get this ???
Person person3("Mia", 35); // // I don't get this ???
cout << person1.toString() << endl;
cout << person2.toString() << endl;
cout << person3.toString() << endl;
return 0;
};