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 6931393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:34:17+00:00 2026-05-27T11:34:17+00:00

I have a normal class called BaseView with a virtual method DisplayView . This

  • 0

I have a normal class called BaseView with a virtual method DisplayView. This method calls GetHeader and GetBody virtual methods to get contents for the page. I would then create a class that inherits from BaseView and override the methods that needs to display content differently than the way the base class does it.

My issue is that, although this works great, when running a code analysis I’m warned not to call the virtual functions directly.

Should I create another class layer on top of the base class that override the virtual functions and only inherit from that?

What are the disadvantages of using the virtual methods directly?

EDIT: the warning is:

CA2214 : Microsoft.Usage : xxx contains a call chain that results in a
call to a virtual method defined by the class. Review the following
call stack for unintended consequences

  • 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-27T11:34:17+00:00Added an answer on May 27, 2026 at 11:34 am

    I think the issue is that DisplayView is virtual, and it’s calling virtual methods. In most cases virtual methods are called by final methods as a means of changing behaviour, for example in the strategy pattern. If a final method calls a virtual method, the compiler knows that the virtual method will always be called in all deriving classes, and therefore it is valid for the virtual method to exist.

    The fact that you’re calling virtual from virtual means that your design can be called into question: if DisplayView is virtual, another implementation may override it. The current implementation calls the virtual GetHeader but a deriving class may not. Therefore it cannot guarantee that GetHeader is not dead code.

    This is probably what FxCop is drawing your attention to. It wants to know that if you define a virtual method (GetHeader in this case) in a base class that all deriving implementations will use it.

    I would focus on making DisplayView final, or appraise your design in that light.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say have normal class in iOS, called A. I'd like to pass this as
I have a peculiar problem. I created a normal Objective C class called SampleTable.
I have turned a normal PHP class into a library so I can use
I have a base class, which is normal Java class. Three subclasses extend it
I have a class that occasionally gets passed null for File objects. During normal
I have a two classes, a controller called AppController and a class called URLDelegate
I have a design question... I want to create my own image class called
I have following code: public class readSensorsData extends Activity implements SensorListener { /** Called
Imagine I have an entity called Product and a repository for it: public class
I have a class that modifies data via some extension methods. In order to

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.