| www.delorie.com/archives/browse.cgi | search |
| From: | Renato De Leone <deleone AT camserv DOT unicam DOT it> |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | HELP with templates |
| Date: | Wed, 12 May 1999 15:15:17 +0200 |
| Organization: | =?iso-8859-1?Q?Universit=E0?= di Camerino |
| Lines: | 89 |
| Message-ID: | <37397EE0.ADFF172@camserv.unicam.it> |
| NNTP-Posting-Host: | cicnew.unicam.it |
| Mime-Version: | 1.0 |
| X-Trace: | news.cineca.it 926519142 6970 193.204.8.11 (12 May 1999 14:25:42 GMT) |
| X-Complaints-To: | news AT cineca DOT it |
| NNTP-Posting-Date: | 12 May 1999 14:25:42 GMT |
| X-Mailer: | Mozilla 4.5 [en] (Win95; I) |
| X-Accept-Language: | en,it,ja,de |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
This is a multi-part message in MIME format.
--------------8BCFCA9D1F49ED95366A014B
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Maybe this is a FAQ but I was unable to find the answer. What is wrong?
What do I need to add to correctly compile and run the program?
--
Renato De Leone
Universitą di Camerino Dipartimento di Matematica e Fisica
Camerino (MC) ITALY PHONE: +39-737-402532
deleone AT camserv DOT unicam DOT it FAX: +39-737-632525
http://www2.unicam.it/~deleone
--------------8BCFCA9D1F49ED95366A014B
Content-Type: text/plain; charset=us-ascii;
name="all"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="all"
-----------array.h------------------
template <class T> class Array{
private:
T data_[10];
public:
T & set(int k);
T value(int k){return data_[k];}
};
-----------array.cc------------------
#include "array.h"
template <class X> X & Array<X>::set(int k)
{
return data_[k];
}
-----------main.cc------------------
#include <iostream.h>
#include "array.h"
main()
{
Array<int> a;
Array<double> b;
a.set(0) = 1;
b.set(0) = 5.2;
cout << a.value(0) << "\n";
cout << b.value(0) << "\n";
}
----------Makefile------------------
.SUFFIXES: .SUFFIXES .cc
SRC = main.cc array.cc
OBJ = main.o array.o
lista.exe: array.h $(OBJ)
g++ -o array.exe $(OBJ) -lgpp
.cc.o:
g++ -xc++ -c $*.cc -o $*.o
array.o: array.h
main.o: array.h
--------------8BCFCA9D1F49ED95366A014B--
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |