5

How to detect if a class is used polymorphically?

 3 years ago
source link: https://www.codesd.com/item/how-to-detect-if-a-class-is-used-polymorphically.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to detect if a class is used polymorphically?

advertisements

Suppose in one old project (>1M lines), there is a class named Base which has two virtual functions foo and bar

class Base
{
public:
    virtual void foo();
    virtual void bar();
};

class Derived: public Base
{
public:
    virtual void foo();
    virtual void bar();
};

I suspect that Base is not used polymorphically, so foo/bar should not be virtual.

To confirm my ideas, I need to find out whether there is a statement like:

Base *b = new Derived;

but if we pass the pointer among a function, it would be hard to find out, for example:

Base *f()
{
  ...
  Derived *d = /* ... */;
  ...
  return d;
}

Is there any way to do that?


Make Derived inherit privately from Base. This will prevent implicit upcasts making Base* b = new Derived; a compile error.

Related Articles

How to detect a single QR code using OpenCV, Python and zbar

I'm using the bottom camera of an AR Drone to detect a QR code in order for me to know the whereabouts of the drone on a chessboard. The drone hovers over the chessboard, where each single square is a QR code holding the position(e.g. A1, C5, E7, etc

How to detect the iPhone OS version using macros

I would like to detect iPhone OS version in my app. I have tried using detection code but was advised to use macros. Does someone experience, can you post sample code, and what library to use.I am not certain what macros you are being advised to use.

How to detect the calling class in the static static method c

How does one detect the calling class from within a static method such that if the class is subclassed the subclass is detected? (See comment inside MakeInstance) @interface Widget : NSObject + (id) MakeInstance; @end @implementation Widget + (id) Ma

How to detect mobile (iOS and Android) using JSP / Java?

Just wondering if anyone has come across this? Basically, Im looking to detect for iOS and Android using JSP and to be able to conditionally add CSS and JS files to the page. Any ideas?Best way would probably be with the User Agent string. There's ac

How to detect rain on camera vision using OpenCV in C ++

How to recognize rain on camera vision using with OpenCV in C++? Or if somebody stick a sticker on a camera how recognize it with OpenCV in C++? Or if somebody throw color to the camera how can i detect it with OpenCV in C++? Detect these on camera v

How do I import a class to use in a Flex application?

I have an actionscript file that defines a class that I would like to use inside a Flex application. I have defined some custom controls in a actionscript file and then import them via the application tag: <mx:Application xmlns:mx="http://www.adob

How to create a shared class and use it in another swift class

I need to use a shared class for my new project for reusing objects and functions in swift .I also need to know how this can be used in another classes. Thanks in Advance BerryHere is a simple example of how to create 2 classes and using data and fun

How to detect corners of the image using GPUImageHarrisCornerDetectionFilter

I'm trying to crop an image with a square in it by detecting the corners. The method below attempts to find the corners, but I'm not really sure how to finish the process. Any thoughts? The optimal function would detect corners, crop the image using

How to detect if the element exists using a lambda expression in c #?

I've been using a try/catch statement to run through whether or not an element exists when I parse through it. Obviously this isn't the best way of doing it. I've been using LINQ (lambda expressions) for the majority of my parsing, but I just don't k

how to detect a browser back button using the java or jquery script?

Could you please let me know how to detect any browser back button click using java script or jquery? I am using the below : if(window.history && window.history.pushState){ window.history.pushState({page:this.href}, null, 'this.href'); $(window).o

How to detect the type of compression used on the file? (if no file extension is specified)

How can one detect the type of compression used on the file? (assuming that .zip, .gz, .xz or any other extension is not specified). Is this information stored somewhere in the header of that file?You can determine that it is likely to be one of thos

How to invoke the internal class constructor using reflection

I want to create an object of inner class using reflection. This is my class: //outer class public final class EMSToCompMessages { private EMSToCompMessages() {} //inner class public static final class CompTypeConfig extends { private CompTypeConfig(

How to get a CSS class name using Selenium?

I am new in selenium testing. I want to get the css class name using selenium. I am using eclipse and Java for development. <table > <tr class="odd"><td>Odd row</td></tr> <tr class="even"><td>E

C # how to detect the mode of construction used

This question already has an answer here: Programmatically detecting Release/Debug mode (.NET) [duplicate] 2 answers C# if/then directives for debug vs release 11 answers I've an application built in VS2013 (written in C#), how can I know if it was b

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK