Jump to content
Larry Ullman's Book Forums

deoren

Members
  • Posts

    7
  • Joined

  • Last visited

deoren's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. I think you're right. I just need to move on and come back (much) later if it's still not clear. lol, I think that will work. Thanks Larry, much appreciated. On a completely unrelated note, I started off my serious programming efforts years ago with the 1E of your "PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide" book; I still have it on the shelf at work. May you write many more!
  2. Thanks for the reply. Regarding the delay, you're a busy guy, and you're providing free support here on your own site so practicing patience won't hurt me. Yeah, I was trying to find another way to say it without using the word overload. Whenever I read that word, I think of having multiple functions with the same name in the same scope, so I find other uses of the word confusing. I'm not sure why I'm being dense about this, but I find this confusing too: Would the following be equivalent to what you wrote? I know it's not as well written, but I'm hoping to find an equivalent statement so I can get past this mental block. I really appreciate the help.
  3. Larry et al, At the time, I believe that made sense to me, but now it reads pretty poorly. It was the use of the word overloaded in this text that I got hung up on: I've done more reading, and my understanding of overloaded methods/functions is what C++ Pocket Reference sums up so well on page 104: If I'm correct in my understanding, the base class and derived classes are separate scopes, so overloading will not occur. Bjarne Stroustrup had this to say: Would the following be an equivalent to what you were saying? Thanks.
  4. Thanks for the reply. I took the provided pets4.cpp file for the book (peachpit website) and made the changes mentioned on page 260. Original file: pets4.cpp, r25 Modified file: pets4.cpp, r26 Diff file: pets4_page260_sleep_function.diff Note: I forgot to change tabs to spaces or vice verse for consistency. Here is an inline diff if it's helpful: --- pets4.orig.cpp 2008-04-12 15:41:08 -0500 +++ pets4.cpp 2012-02-27 06:34:06 -0600 @@ -38,6 +38,7 @@ // Overloaded method: void bark(int count); + void sleep(int hours); }; @@ -91,6 +92,11 @@ void Dog::bark(int count) { std::cout << name << " barks " << count << " times\n"; } + +void Dog::sleep(int hours) +{ + std::cout << name << " sleeps " << hours << " hours"; +} // Start the main() function. int main() { @@ -104,8 +110,8 @@ cat.eat(); cat.climb(); cat.play(); - - dog.sleep(); + + dog.sleep(); dog.eat(); dog.bark(); dog.play();
  5. Thanks for the reply Larry. I understand what was said on the thread about: A derived class function with a different signature than a base class function will result in the base class function of the same name being hidden. A derived class function with the same name and signature as the base class will override the base class function. This is the part I've gotten fixated on: Please correct me, but with an overloaded function, wouldn't you generally use one of the functions and depending on what function signature you use, that determines what function gets called? In this case: sleep(int hours) since the base class sleep function is hidden, don't you end up with just one function available to the dog class? At least running the pets4.cpp file through a compiler with this new function: void Dog::sleep(int hours) { std::cout << name << " sleeps " << hours << " hours"; } and calling it like so: dog.sleep(); results in this error:
  6. First, thanks to both of you for writing the book and for how well the content is explained. However I'm having trouble understanding this statement on page 260: From what I can find via Google searches and tinkering with the pets4.cpp code, having a method in the derived class with the same name (different signature or not) as one in the base class hides the base class method, much like overriding a method seems to. Can you maybe explain that in a different way so it makes more sense to me? Thanks in advance!
×
×
  • Create New...