Article View: gnu.g++.bug
Article #242Clarification of constructor/operator= problem
From: Jason Merrill
Date: Sun, 12 Apr 1992 11:36
Date: Sun, 12 Apr 1992 11:36
32 lines
1201 bytes
1201 bytes
This code demonstrates the bug:
-----
class Bunk {
int d;
public:
Bunk(int i) { d = i; }
};
main() {
Bunk b(1); // works (calls Bunk(int))
Bunk a(b); // works (copies b into a w/o fn call)
Bunk* ap = new Bunk(b); // ERROR: tries to call Bunk(int) with b
a = b; // works
a.operator=(b); // ERROR: can't find operator=(Bunk&)
return 0;
}
-----
Errors:
test.cc: In function `int main ()':
test.cc:10: bad argument 0 for function `Bunk::Bunk (int)' (type was class
Bunk)
test.cc:12: no member function `Bunk::operator ='
So the most obvious uses of the copy constructor and operator= are covered.
However, the use of T* = new T(T&) is rather common...
--
Jason Merrill
jason@jarthur.claremont.edu
Technical Details
Message-ID:
<1992Apr12.113635.23324@muddcs.claremont.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!jarthur.claremont.edu!jasonShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!jarthur.claremont.edu!jason From: jason@jarthur.claremont.edu (Jason Merrill) Subject: Clarification of constructor/operator= problem Message-ID: <1992Apr12.113635.23324@muddcs.claremont.edu> Sender: gnulists@ai.mit.edu Organization: Harvey Mudd College Distribution: gnu Date: Sun, 12 Apr 1992 11:36:35 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 33