Pure virtual implementation, or not.

This is a discussion on Pure virtual implementation, or not. within the C++ Programming forums, part of the General Programming Boards category; VC6/VC.NET says allows implementation of pure virtual functions. The comeau online compiler does not. In "Effective C++" Scott Meyers provides ...

  1. #1
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361

    Pure virtual implementation, or not.

    VC6/VC.NET says allows implementation of pure virtual functions.
    The comeau online compiler does not.
    In "Effective C++" Scott Meyers provides an implementation for a pure virtual function and calls it from a derived type.

    WHAT IS THE VERDICT? Does anyone have a copy of the standard to look this up in? I just had a discussion with someone about whether or not pure virtual functions could have an implementation or not. I'd REALLY love to know the answer. Thanks.

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    yes it is allowed to provide a body for a pure virtual function. This is most commonly done with pure virtual destructors but sometimes is useful with pure virtual functions. I'm surprised the comeau compiler disallows it. It shouldnt.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Update: I got the comeau compiler to compile implementation for a pure virtual function by seperating interface from implementation...

    like
    Code:
    class a
    {
       virtual void fn() = 0 { dosomething(); }
    };
    Won't compile but
    Code:
    class a
    {
       virtual void fn() = 0;
    };
    
    void a::fn()
    {
       dosomething();
    }
    Will.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. Replies: 11
    Last Post: 03-03-2008, 11:27 AM
  3. Information Regarding Pure Virtual Functions
    By shiv_tech_quest in forum C++ Programming
    Replies: 6
    Last Post: 01-29-2003, 03:43 AM
  4. C++ XML Class
    By edwardtisdale in forum C++ Programming
    Replies: 0
    Last Post: 12-10-2001, 10:14 PM
  5. Exporting Object Hierarchies from a DLL
    By andy668 in forum C++ Programming
    Replies: 0
    Last Post: 10-20-2001, 01:26 PM

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