|
-
May 19th, 2009, 08:22 PM
#1
Variables and Class Constructors
I was just wondering what the best way is to assign private variables a value within the constructor.
For example;
Option 1: //Which uses the private variable directly
Book::Book(string author)
{
_Author = author;
}
or Option 2 //Call a method to do it for me
Book::Book(string author)
{
AddAuthor(author);
}
With option 2, its invoking its public method and I could have checks stopping null values etc however it would be using more memory? I could really do the same thing in option 1, how ever would it be creating redundant code since I have a Method that does it?
thanks in advance.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|