possibly a stupid question about inheritance

This is a discussion on possibly a stupid question about inheritance within the C++ Programming forums, part of the General Programming Boards category; let's say I've got two classes: Socket and SecureSocket. SecureSocket is derived publicly from Socket, and both classes implement Send() ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    2,499

    possibly a stupid question about inheritance

    let's say I've got two classes: Socket and SecureSocket. SecureSocket is derived publicly from Socket, and both classes implement Send() and Recv() methods. Socket additionally implements RecvLine(), which calls Recv(), but SecureSocket does not. if I have a SecureSocket object, and I call RecvLine() on it, will it call the Socket version of Recv() or will it call the SecureSocket implementation?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You couldn't have written an example with classes foo and bar to check in the same time it took you to make this post?

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    2,499
    Quote Originally Posted by tabstop View Post
    You couldn't have written an example with classes foo and bar to check in the same time it took you to make this post?
    I certainly could if I were on my dev computer, but I'm on my cell phone.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Elkvis View Post
    I certainly could if I were on my dev computer, but I'm on my cell phone.
    Oh. Well in that case, brewbuck's now-vanished post was the right answer: it depends on whether the function is virtual.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    Actually, as long as that method is accessible it shouldn't matter whether the function is virtual.

    SecureSocket does not implement RecvLine, correct? If that's the case, then any call to RecvLine will call the base class version.

    Edit: I think I misunderstood the question. tabstop is right that Socket's RecvLine will call SecureSocket's Revc only if Recv is virtual in Socket.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Question Probably
    By Kyrin in forum C Programming
    Replies: 2
    Last Post: 05-07-2006, 12:51 AM
  2. Replies: 7
    Last Post: 11-03-2005, 11:17 PM
  3. Stupid Question
    By digdug4life in forum C++ Programming
    Replies: 22
    Last Post: 05-17-2005, 11:43 AM
  4. stupid, stupid question
    By xelitex in forum C++ Programming
    Replies: 5
    Last Post: 12-22-2004, 07:22 PM
  5. stupid question
    By maes in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 11-08-2001, 10:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21