From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,9ff2206c0a9e293e,start X-Google-Attributes: gid109fba,public X-Google-Thread: f678f,9ff2206c0a9e293e,start X-Google-Attributes: gidf678f,public X-Google-ArrivalTime: 1995-02-20 12:00:48 PST Newsgroups: comp.unix.osf.misc,comp.lang.c++ Path: nntp.gmd.de!newsserver.jvnc.net!nntpserver.pppl.gov!princeton!gw1.att.com!fnnews.fnal.gov!uwm.edu!news.alpha.net!news.mathworks.com!uunet!newsflash.concordia.ca!nstn.ns.ca!cs.dal.ca!kelley From: kelley@cs.dal.ca (Dan Kelley) Subject: Could somebody pls try this C++ test program on ALPHA/OSF? Message-ID: Keywords: c++ test alpha osf Sender: usenet@cs.dal.ca (USENET News) Nntp-Posting-Host: skye.phys.ocean.dal.ca Organization: Oceanography, Dalhousie University, Halifax, NS, Canada Date: Mon, 20 Feb 1995 20:00:48 GMT Xref: nntp.gmd.de comp.unix.osf.misc:2408 comp.lang.c++:91806 Hi. I am trying to compile a c++ program on an alpha/osf machine, and having difficulties. Would somebody be so kind as to try compiling it on their machine? I'd like to learn whether the c++ compiler on this particular machine is installed incorrectly, or whether the alpha c++ compiler is faulty. The program compiles fine with g++ on my sun. (Note: I'm uncertain of whether the compiler was installed correctly because it was installed by somebody else -- a scientist, not a system person -- on a friends machine I've just recently got access to.) Thanks very much in advance. This should only take a moment of your time if you try it. *** DEMO OF FAILURE TO LINK ON ALPHA MACHINE *** % cxx test.cc | & demangle ld: Unresolved: MyVector::MyVector(int) MyVector::push_back(const float&) MyVector::operator ()(unsigned int) *** TEST PROGRAM *** #include #include static const int CAPACITY_DEF = 16; template class MyVector { public: MyVector(int capacity = CAPACITY_DEF); // default capacity ~MyVector() {delete [] contents;} // clean up void push_back(const T& a); // store an item at top T& operator() (unsigned int offset); // get item at index unsigned size() const {return the_depth;} // get present depth protected: int the_capacity; // max elements int the_depth; // number elements now T* contents; // can hold capacity elements void enlarge(); // double capacity void err(const char *msg) const; // for debugging }; template MyVector::MyVector(int capacity = CAPACITY_DEF) { contents = new T[the_capacity = capacity]; if (!contents) err("\nOut of memory\n"); the_depth = 0; } // Push at back of list template void MyVector::push_back(const T& item) { while (the_depth > the_capacity - 1) enlarge(); // only done once, actually contents[the_depth++] = item; } template void MyVector::enlarge() { if (the_capacity > 1) the_capacity *= 2; else the_capacity = 2; T* contents_new = new T[the_capacity]; if (!contents_new) err("\nOut of memory\n"); for (int i = 0; i < the_depth; i++) contents_new[i] = contents[i]; delete [] contents; contents = contents_new; } template T& MyVector::operator()(unsigned int offset) { if (offset < the_capacity) return contents[offset]; else { char msg[100]; sprintf(msg, "Index %d is out of bounds (limit is 0 to %d)\n", offset, the_depth); err(msg); return contents[0]; // to prevent compiler error } } template void MyVector::err(const char *msg) const { cerr << msg; exit(1); } int main(int argc, char *argv[]) { MyVector a; for (int i = 0; i < 10; i++) { a.push_back(float(0.1 * i)); //a.push_back(0.1 * i); // wrong on gcc } for (i = 0; i < 10; i++) { cout << "a[" << i << "] = " << a(i) << "\n"; } return 0; }