🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.help
Article #131

Simple Question

#131
From: Tim Budd
Date: Thu, 30 Jul 1992 16:36
29 lines
1367 bytes
Let me appologize in advance for what is probably a trivial question,
and one that is probably asked incessantly.  Our support people seemed to 
have installed g++ 2.2.2, but I can't locate any of the documentation or
test cases.  I can get templates to work within a single file, but not
split between two files.  Can somebody explain what I must do to get
the following minimalist program to work.  At present it produces linker
errors (at least on my machine).

------file box.h ------------------
template <class T> class box {
public:
	box(T val);
	T getValue();
private:
	T value;
};
-----file box.cc -----------------
# include "box.h"
template <class T> box<T>::box(T val) : value(val) { }
template <class T> T box<T>::getValue() { return value; }
-----file test.cc --------------
# include "box.h"
# include <iostream.h>
main() {
	box<int> aBox(7);
	cout << "abox contains " << aBox.getValue() << '\n';
}

many thanks.
Technical Details
Message-ID: <1992Jul30.163635.2036@CS.ORST.EDU>
Path: arc1-ca.pugleaf.net!sparky!uunet!darwin.sura.net!jvnc.net!rutgers!orstcs!fog.CS.ORST.EDU!budd

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!darwin.sura.net!jvnc.net!rutgers!orstcs!fog.CS.ORST.EDU!budd
From: budd@fog.CS.ORST.EDU (Tim Budd)
Newsgroups: gnu.g++.help
Subject: Simple Question
Message-ID: <1992Jul30.163635.2036@CS.ORST.EDU>
Date: 30 Jul 92 16:36:35 GMT
Sender: usenet@CS.ORST.EDU
Distribution: gnu
Organization: Oregon State University, Computer Science Dept.
Lines: 29
Nntp-Posting-Host: fog.cs.orst.edu