Thread: pclose() vs fclose()?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    No, I wouldn't do that. RAII objects are kept on the stack, and that's a bad place for polymorphism. If the F and P variants have any common code, make the base's destructor protected and non-virtual.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by CornedBee View Post
    No, I wouldn't do that. RAII objects are kept on the stack, and that's a bad place for polymorphism. If the F and P variants have any common code, make the base's destructor protected and non-virtual.
    What do you mean it's bad practice for polymorphism?
    All the Auto*Close classes are exactly the same except for the destructors; so rather than copy & pasting the same code over and over, why not just inherit an abstract base class and just override the destructor?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fclose slow
    By Rmantingh in forum C Programming
    Replies: 4
    Last Post: 04-08-2010, 11:01 AM
  2. Question about fclose
    By ulillillia in forum C Programming
    Replies: 6
    Last Post: 05-31-2007, 01:31 AM
  3. pclose without waiting for child
    By Largo in forum C Programming
    Replies: 1
    Last Post: 11-26-2005, 05:13 AM
  4. fclose()
    By GanglyLamb in forum C Programming
    Replies: 4
    Last Post: 11-11-2002, 08:45 AM
  5. quick fclose question
    By ihatejava in forum C Programming
    Replies: 5
    Last Post: 10-10-2002, 03:56 PM