Mail Archives: djgpp/1995/10/10/08:23:11
| Xref: | news-dnh.mv.net comp.os.msdos.djgpp:2531 | 
| Path: | news-dnh.mv.net!mv!news.sprintlink.net!EU.net!Germany.EU.net!wizard.pn.com!satisfied.apocalypse.org!news2.near.net!ctp.com!news | 
| From: | pdrap AT ctp DOT com (Patrick Draper) | 
| Newsgroups: | comp.os.msdos.djgpp | 
| Subject: | More info with the template problem | 
| Date: | Tue, 10 Oct 1995 07:31:14 GMT | 
| Organization: | Cambridge Technology Partners | 
| Lines: | 109 | 
| Reply-To: | pdrap AT ctp DOT com | 
| Nntp-Posting-Host: | vuitpc08.nl.ctp.com | 
| To: | djgpp AT sun DOT soe DOT clarkson DOT edu | 
| Dj-Gateway: | from newsgroup comp.os.msdos.djgpp | 
I'm including more information with the template problem that I'm having.
In my research of how gcc handles templates, I ran across the web page that
explains how to make templates work with gcc, but I can't figure out
exactly how to get it to compile.
I've included a very tiny example, and the compiler output to show my
problem. The compiler that I'm using is DJGPP 1.12 maint 3, and the gcc
version is 2.6.3.
------------------------------------------------------------------------------------------------------------
File: templates.h
------------------------------------------------------------------------------------------------------------
template <class T>
class A {
     public:
       void f ();
       T t;
};
     
template <class T> void g (T a);
------------------------------------------------------------------------------------------------------------
File: templates.cc
------------------------------------------------------------------------------------------------------------
#include "templates.h"
     
template <class T>
void A<T>::f () { }
     
template <class T>
void g (T a) { }
// explicit template instantiation These lines are here because
// the FAQ said that they had to be there to work with gcc.
template class A<int>
template void g (A<int>);
------------------------------------------------------------------------------------------------------------
File: main.cc
------------------------------------------------------------------------------------------------------------
#include "templates.h"
     
main ()
{
  A<int> a;
  a.f ();
  g (a);
}
------------------------------------------------------------------------------------------------------------
File: makefile
------------------------------------------------------------------------------------------------------------
CC=gcc
CFLAGS=-Wall
LIBS=-lm -lgpp
..cc.o:
	$(CC) -c $(CFLAGS) -o $*.o $<
LIBOBJS=main.o templates.o
main:  $(LIBOBJS)
	gcc $(CFLAGS) -o main $(LIBOBJS) $(LIBS)
main.o: main.cc templates.h
templates.o: templates.cc templates.h
------------------------------------------------------------------------------------------------------------
Compiler output
------------------------------------------------------------------------------------------------------------
c:> make
gcc -c -Wall -o main.o main.cc
gcc -c -Wall -o templates.o templates.cc
templates.h:11: parse error at null character
make.exe: *** [templates.o] Error 1
As you can see, the advice in the FAQ doesn't help! What am I missing here?
Thanks,
- Raw text -