Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8014653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:00:25+00:00 2026-06-04T20:00:25+00:00

I was reading Never Call Virtual Functions during Construction or Destruction by Scott Meyer

  • 0

I was reading Never Call Virtual Functions during Construction or Destruction by Scott Meyer about basic C++ usage.

I was wondering if g++ has some compiler flags to warn about this bad coding that is really effective. If not what could be a way to code to do this check?

If I would code such kind of check I would approach this job by using a stack and inserting a piece of information at each call (a way to implement a call stack.

What I still need is a way to test whether a function is a virtual or whether a function is a constructor: Is there anyway to do that that you know? Something similar to a .NET ‘reflection’ idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:00:27+00:00Added an answer on June 4, 2026 at 8:00 pm
    > cat nevercall.cpp             
    class Transaction {
    public:
        Transaction();
        virtual void logTransaction() const = 0;
    
        // ...
    };
    
    Transaction::Transaction()
    {
        //...
        logTransaction();
    }
    
    class BuyTransaction: public Transaction {
    public:
        virtual void logTransaction() const;
    
        //...
    };
    
    class SellTransaction: public Transaction {
    public:
        virtual void logTransaction() const;
    
        // ...
    };
    
    int main()
    {
        BuyTransaction b;
    }
    

    Using -Weffc++ warns about this if (and only if) virtual void Transaction::logTransaction() const is pure, as it is in Meyer’s sample code:

    > g++ -Weffc++ nevercall.cpp -o nevercall
    nevercall.cpp:1:7: warning: 'class Transaction' has virtual functions and accessible non-virtual destructor [-Wnon-virtual-dtor]
    nevercall.cpp: In constructor 'Transaction::Transaction()':
    nevercall.cpp:12:20: warning: pure virtual 'virtual void Transaction::logTransaction() const' called from constructor [enabled by default]
    nevercall.cpp: At global scope:
    nevercall.cpp:15:7: warning: 'class BuyTransaction' has virtual functions and accessible non-virtual destructor [-Wnon-virtual-dtor]
    nevercall.cpp:22:7: warning: 'class SellTransaction' has virtual functions and accessible non-virtual destructor [-Wnon-virtual-dtor]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Reading about Kohana templates and saw something I've never seen before: $this->template->title = __('Welcome
I've been reading about OOP in C but I never liked how you can't
When reading about JQuery best practices, I read this recently: Never include Javascript events
Reading about ECMAScript 5's strict mode I learn that: Certain language functions are so
I've never wandered into reading binary data before. I'm trying to learn now, and
Delphi Windows Service Design I've never created a windows service but have been reading
I am reading the tutorial at http://code.google.com/p/google-web-toolkit-incubator/wiki/LoginSecurityFAQ It states Remember - you must never
What's the deal with iPhone's GPS? I never get a good reading when i'm
So I've never done any assembly programming (although I did some reading/reasoning out the
I've been reading up on this whole subject, but I never came across this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.