Protected purely virtual function

This is a discussion on Protected purely virtual function within the C++ Programming forums, part of the General Programming Boards category; Hi, Trying to generalize behaviour of a set of classes and to supply them with decorators, I'm implementing an abstract ...

  1. #1
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248

    Protected purely virtual function

    Hi,

    Trying to generalize behaviour of a set of classes and to supply them with decorators, I'm implementing an abstract interface containing the common functions.

    Now all my classes have a 'protected' member function "Update()" , which I thus make a protected purely virtual function in my base class.

    Does this make sense ? I've seen something written on this, but I forgot where and what they said.

    I can think of some polymorphic call-back, but this is not the way the function is used. Perhaps I'll just make it a public function? This will not have a negative impact on the code.

    Thanks a lot for your answers !

    Mark

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    Where will that function be called?

  3. #3
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248
    Code:
    A::Update()
    will only be called in A's member functions.

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,249
    If it's not used polymorphically it doesn't need to be virtual.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    >> will only be called in A's member functions.
    Then you can make it private.

    It can still be virtual. If you want derived classes to have the opportunity to override it with different code. But if you're only calling it from A then you should make it private in A.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with virtual function calls, please help
    By e66n06 in forum C++ Programming
    Replies: 12
    Last Post: 12-12-2007, 04:12 AM
  2. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 12:03 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM

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