|
PC-lint/FlexeLint Output | Reference Manual Explanation | Home Page bug1732.cpp
This program has a serious flaw. With one compiler it printed "2000"; with another it produced an 'illegal operation'. Can you spot the bug? bug1732.cpp lint Output
--- Module: bug1732.cpp
_
WhiteHouse(int n) { p = new int; *p = n; }
bug1732.cpp(6) : Info 1732: new in constructor for class 'WhiteHouse' which has
no assignment operator
bug1732.cpp(6) : Info 1733: new in constructor for class 'WhiteHouse' which has
no copy constructor
_
};
bug1732.cpp(8) : Info 1712: default constructor not defined for class
'WhiteHouse'
Reference Manual Explanation
1732 new in constructor for class 'Name' which has no
assignment operator -- Within a constructor for the cited
class, there appeared a new. However, no assignment
operator was declared for this class. Presumably some
class member (or members) points to dynamically allocated
memory. Such memory is not treated properly by the
default assignment operator. Normally a custom assignment
operator would be needed. Thus, if x and y are both of
type Name
x = y;
will result in pointer duplication. A later delete would
create chaos. [12, Item 11]
If you have comments or questions about this bug, please post them to our Discussion Forum |
Previous Bug - Bug #1544 - December 2002