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

            bug1557.cpp

1     #include <stdio.h>
2
3     class A { public: int a, b; };
4     class B
5         {
6       public:
7         const A a;
8         B() :a() { }
9         };
10
11    int main()
12        {
13        B b;
14        printf( "%d %d\n", b.a.a, b.a.b );
15        return 0;
16        }

Our programmer was having a few difficulties so he reduced his program down to the above simple example and was amazed to find that it did not print zeros. What's going on?


bug1557.cpp lint Output

--- Module:   bug1557.cpp
           _
    B() :a() { }
bug1557.cpp(8) : Warning 1557: const member 'B::a' is not initialized
bug1557.cpp(8) : Warning 1401: member 'B::a' (line 8) not initialized by constructor

Reference Manual Explanation


1557  const member 'Symbol' is not initialized  -- A class member typed const class
      (or struct or union) is mentioned in a constructor initializer list. But the
      class (or struct or union) referenced has no constructor and hence the member
      is not initialized.  See also message  1769.

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

Previous Bug - Bug #551 - October 2003

PC-lint/FlexeLint - Product Overview

Home | Contact | Order

PC-lint and FlexeLint are trademarks of Gimpel Software
Copyright 2003, Gimpel Software