barney_1
March 11th, 2007, 04:55 PM
Hi Folks,
I'm using a book called "Teach Yourself C++" by Herbert Schildt to learn the language. I used a java based lecture called Thinking in C by Bruce Eckel to get me ramped up for C++.
In the book, I'm doing the exercises for section 1.5 where I am supposed to write a program that uses a class to store information on library book. I need to store title, author, and number on hand. I am able to do this but when I look up the answer in the back I find that he used pointers and I didn't. Here is the function I have questions about:
void card::store(char *t, char *name, int num);
{
strcpy(title, t);
strcpy(author, name);
number = num;
}
So, 'title' and 'author' are private char's from the class 'card'. What I don't understand is that in the main function of the program this function is passed strings but as you can see in the declaration of the card::store function he is using the pointers *t and *name. Why is the use of pointers here better than the use of something like 'char t[]'?
I'm using a book called "Teach Yourself C++" by Herbert Schildt to learn the language. I used a java based lecture called Thinking in C by Bruce Eckel to get me ramped up for C++.
In the book, I'm doing the exercises for section 1.5 where I am supposed to write a program that uses a class to store information on library book. I need to store title, author, and number on hand. I am able to do this but when I look up the answer in the back I find that he used pointers and I didn't. Here is the function I have questions about:
void card::store(char *t, char *name, int num);
{
strcpy(title, t);
strcpy(author, name);
number = num;
}
So, 'title' and 'author' are private char's from the class 'card'. What I don't understand is that in the main function of the program this function is passed strings but as you can see in the declaration of the card::store function he is using the pointers *t and *name. Why is the use of pointers here better than the use of something like 'char t[]'?