Thread: Protected purely virtual function

  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,366
    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
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    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,366
    >> 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, 05:12 AM
  2. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM