Thread View: comp.sys.sgi.bugs
2 messages
2 total messages
Started by Peter Foldiak
Tue, 19 Mar 1996 19:43
C++ template "already defined" error - any ideas?
Author: 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
Re: C++ template "already defined" error - any ideas?
Author: Barbara Anderson-Zayat
Date: Thu, 21 Mar 1996 17:07
Date: Thu, 21 Mar 1996 17:07
41 lines
1600 bytes
1600 bytes
Peter Foldiak (pf2@st-andrews.ac.uk) wrote:
: 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!
Try including this in list.h ...
#ifdef __LIST_H_
#define __LIST_H_
// contents of list.h
#endif
It sounds like somehow your list.h is getting included twice.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads