Article View: comp.sys.sgi.bugs
Article #99C++ template "already defined" error - any ideas?
From: Peter Foldiak
Date: Tue, 19 Mar 1996 19:43
Date: Tue, 19 Mar 1996 19:43
93 lines
2595 bytes
2595 bytes
I would like to ask for some help with the following problem that seems
to be specific to the SGI CC compiler (Delta/C++), (as Turbo C does not
seem to give similar error messages.)
I tried to simplify the files as much as possible.
If you have any ideas what the problem may be please email me
directly or send a copy of your followup by email
(mailto:pf2@st-andrews.ac.uk) Thanks!
When I try to compile the files below on a SG Indy (Irix 5.3) I get the
following error:
----
% CC main.c list.c
main.c:
"list.h", line 1: error(3328): class template "list" has already been
defined
template<class T> class list {
^
1 error detected in the compilation of "main.c".
list.c:
%
----
(By the way, how do I find out what error(3328) is in more detail?)
If I concatenate list.c and main.c into a file called listmain.c,
and compile with
% CC listmain.c
%
the error message disapprears! So I guess it has something to do
with the bits being in separate files.
Also, if the files contain no templates there is no error.
Could anyone please help? Any ideas?
Is there something special with including headrers when I use templates?
Thanks!
Peter
-
===========================================
The files that won't compile:
list.h:
-------
template<class T> class list {
T x;
list *next;
public:
list<T>::list();
};
list.c:
-------
#include <stdio.h>
#include "list.h"
template<class T> list<T>::list()
{
next = NULL;
}
main.c:
-------
#include "list.h"
int main()
{
list<int> q;
return 0;
}
=======================================
This file compiles without error:
listmain.c:
-----------
#include <stdio.h>
#include "list.h"
template<class T> list<T>::list()
{
next = NULL;
}
int main()
{
list<int> q;
return 0;
}
--
Peter Foldiak http://psych.st-and.ac.uk:8080/~pf2
Psychological Laboratory phone: +44 1334 462087
University of St Andrews fax: +44 1334 463042
St Andrews KY16 9JU, U.K. e-mail: Peter.Foldiak@st-and.ac.uk
Technical Details
Message-ID:
<4in2p7$27b@calvin.st-and.ac.uk>Path:
arc1-ca.pugleaf.net!yama.mcc.ac.uk!liv!strath-cs!st-and!pf2Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!yama.mcc.ac.uk!liv!strath-cs!st-and!pf2 From: pf2@st-andrews.ac.uk (Peter Foldiak) Newsgroups: comp.sys.sgi.bugs,comp.sys.sgi.apps,comp.sys.sgi.misc,comp.lang.c++ Subject: C++ template "already defined" error - any ideas? Date: 19 Mar 1996 19:43:35 GMT Organization: University Of St. Andrews, Fife, UK. Message-ID: <4in2p7$27b@calvin.st-and.ac.uk> NNTP-Posting-Host: psych.st-and.ac.uk NNTP-Posting-User: pf2