Hello All, this is my first post here, I was a novice Pascal and C programmer back in the DOS days, now I am taking a C++ class based on "Programming - Principles and Practices Using C++" by Bjarne Stroustrup. In the book he gives an example in which he is explaining about "Tokens"... I have pared that down to the bare bones and I am comparing it to an example from Wikipedia. I have made these two programs functionally equivalent.
I have two main questions: 1) What do you call these? They are not really "Tokens", that is just a term that Mr. Stroustrup came up with as a teaching concept according to my instructor.
This first program is a modified version of one of the examples from the book:
#include <iostream>
#include <string>
using namespace std;
class person
{
public:
string name;
int age;
person(string name_str, int age_int)
:name (name_str), age(age_int) { }
};
int main()
{
char ch;
person t1("Calvin", 30);
person t2("Hobbes", 20);
cout << t1.name << ": " << t1.age << endl;
cout << t2.name << ": " << t2.age << endl;
cin >> ch;
return 0;
}
This one is an example taken from Wikipedia about "Classes":
#include <iostream>
#include <string>
using namespace std;
class person
{
public:
string name;
int age;
};
int main ()
{
char ch;
person a, b;
a.name = "Calvin";
b.name = "Hobbes";
a.age = 30;
b.age = 20;
cout << a.name << ": " << a.age << endl;
cout << b.name << ": " << b.age << endl;
cin >> ch;
return 0;
}
2) My second question is: when or why would we want to use each? It seems the first one, the "Token" one (for lack of a better term) is more work than the one that is from the "Classes" example.
Again, I would like to know how to more accurately refer to these as well as when and why to use each.
Thank you so much in advance.
Gary
ps - this is a super-nice forum, the best I have seen!