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

  • Home
  • SEARCH
  • 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 6682083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:39:52+00:00 2026-05-26T04:39:52+00:00

When overriding a virtual method, I noticed that when I make a mistake in

  • 0

When overriding a virtual method, I noticed that when I make a mistake in the visibility (protected method overridden as a public method), I’m not warned by the compiler.

It is valid C++, but usually it is a mistake.

For example:

#include <iostream>

class Base
{
protected:
  virtual void ProtectedMethod(void)
  {
    std::cout << "Base::ProtectedMethod" << std::endl;
  }
};

class Derived : public Base
{
public:
  virtual void ProtectedMethod(void)
  {
    std::cout << "Derived::ProtectedMethod" << std::endl;
  }
};

int main(int, char* [])
{
  Derived d;
  d.ProtectedMethod();
}

I tried compiling with gcc and clang, with -Wall -Wextra, with no luck.
I ran CppCheck on this code, still no luck.

What tool can help me detect this ?
I need to fix the whole sources of a library I’m working on.

  • 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-05-26T04:39:52+00:00Added an answer on May 26, 2026 at 4:39 am

    I found a solution to my needs using ctags.

    CTags can parse C++ and dump information to a file.

    Using the following options:

    $CTAGS -f $TAGFILE --fields=fkstia --c++-kinds=+p  -R $SOURCES
    

    I can get all the needed information in an easily parseable format.

    Piping $TAGFILE through a few grep commands, I can verify that a known function name has the expected visibility, and issue a warning with the incriminated file otherwise.

    Here is a bash snippet to extract info from the ctags output :

    #!/bin/bash
    function check_method {
        echo "Checking $1 (should be $2 and is not)"
        cat $TAGFILE | grep "^$1    " | grep "access" | grep -v "access:$2" | cut -f 2
        echo
    }
    
    # will warn anytime a method called ProtectedMethod is not protected
    check_method ProtectedMethod protected
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I noticed that when overriding virtual methods in C# using Visual Studio, the IDE
I'm trying to override an overridden method (if that makes sense!) in C#. I
When overriding a non-virtual method in Java, use of the @Override annotation is recommended,
In C#, is it possible to mark an overridden virtual method as final so
I'm creating a class named TetraQueue that inherits System.Collections.Generic.Queue class overriding the Dequeue method,
I'm overriding a virtual method, and I want to call inherited . But I
Most modifiers make sense to me - abstract, protected etc. But virtual seems a
The communication object, ExtendingWCFwithServiceHost.clsMyOwnHost, has overridden the virtual function OnOpening but it does not
In C++, a subclass can specify a different return type when overriding a virtual
When overriding the equals() function of java.lang.Object, the javadocs suggest that, it is generally

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.