Article View: gnu.g++.bug
Article #216static members and g++ 2.2.2
From: Scott Sutherland
Date: Mon, 10 Aug 1992 16:24
Date: Mon, 10 Aug 1992 16:24
56 lines
1742 bytes
1742 bytes
GNU g++ 2.2.2 doesn't seem to like static members at all. The following
compiles correctly with g++ 1.40.3, but when I compile it with g++ 2.2.2 (on
a SUN 4/470, OS 4.1.1), I get an undefined reference for the static member:
mathlab <Greg> g++ test.cc
ld: Undefined symbol
__7nothing$field
collect: /usr/bin/ld returned 2 exit status
Here's the program:
#include <stream.h>
class nothing{
private:
static int field=0;
public:
inline message() {cout << "my field is " << field << "\n";}
nothing() ; //constructor
};
nothing::nothing()
{
if (field) {
cout << "field value " << field << " detected by the constructor\n";
return;
}
cout << "initialize the field (enter a non-zero value)\n";
cin >> field;
}
main()
{
cout << "initalize x\n";
nothing x; //a call to the constructor
cout << "initalize y\n";
nothing y; //another call to the constructor
cout << "check x: ";
x.message();
cout << "check y: ";
y.message();
}
Suggestions? Please respond via email (post if you want, too)
Scott Sutherland
scott@math.sunysb.edu
Stony Brook Institute for Mathematical Sciences
--
Scott Sutherland
scott@math.sunysb.edu
Stony Brook Institute for Mathematical Sciences
Technical Details
Message-ID:
<1992Aug10.162409.1831@sbcs.sunysb.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!mathlab.mathlab.sunysb.edu!scottShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!mathlab.mathlab.sunysb.edu!scott From: scott@mathlab.mathlab.sunysb.edu (Scott Sutherland) Subject: static members and g++ 2.2.2 Message-ID: <1992Aug10.162409.1831@sbcs.sunysb.edu> Sender: gnulists@ai.mit.edu Organization: SUNY at Stony Brook, Dept. of Math Distribution: gnu Date: Mon, 10 Aug 1992 16:24:09 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 57