Click on image to see enlargment

PC-lint/FlexeLint Output | Reference Manual Explanation | Home

            bug1506.cpp

1    #include <stdio.h>
2
3    class Animal
4        {   public:
5        virtual void init() {}
6        Animal() { init(); }
7        };
8
9    class GroundHog : public Animal
10       {   public:
11       const char *appears;
12       virtual void init() { appears = "Feb 2"; }
13       };
14
15   int main()
16       {
17       GroundHog x;
18       printf( "Ground hogs appear %s\n" , x.appears );
19       return 0;
20       }

Our ground hog is not appearing on schedule. What's the problem?


bug1506.cpp lint Output

--- Module:   bug1506.cpp (C++)
                   _
    Animal() { init(); }
bug1506.cpp(6) : Warning 1506: Call to virtual function 'Animal::init(void)'
    within a constructor or destructor

Reference Manual Explanation


1506   Call to virtual function 'Symbol' within a constructor or
       destructor  -- A call to a virtual function was found in a
       constructor or a destructor of a class.  If this class is a base
       class of some other class (why else make a virtual call?), then
       the function called is not the overriding function of the derived
       class but rather the function associated with the base class.  If
       you use an explicit scope operator this message will not be
       produced.


If you have comments or questions about this bug, please post them to our   Discussion Forum


Previous Bug - Bug #1401 - January 2007

[ new ] Use our Interactive Demo to Run FlexeLint on our Bugs of the Month

PC-lint/FlexeLint - Product Overview

Home | Contact | Order

PC-lint and FlexeLint are trademarks of Gimpel Software
Copyright 2007, Gimpel Software, All rights reserved.