public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Link error ....redefinition of......
@ 2009-06-02  6:16 Alex Luya
  2009-06-02  6:34 ` Tim München
  0 siblings, 1 reply; 2+ messages in thread
From: Alex Luya @ 2009-06-02  6:16 UTC (permalink / raw)
  To: GCC, GCC-Help

I download source code for book <</Data Structures and Algorithm 
Analysis in C++ (Second Edition), /by Mark Allen Weiss>> 
from:http://users.cs.fiu.edu/~weiss/dsaa_c++/code/,try to compiler 
it,but got many errors,most of them say:
...... previously declared here
.......: redefinition of .....

I think template causes these errors,but how to fix it.
-----------------------------------------------------------------------
My configuration:
Ubuntu 9.04
GCC version 4.3.3 (Ubuntu 4.3.3-5ubuntu4)
Eclipse 3.4
CDT:.5.0.2
-------------------------------------------------------------------------

Files  and error message are following:

StackAr.h
-----
        #ifndef STACKAR_H
        #define STACKAR_H

        #include "../vector.h"
        #include "../dsexceptions.h"

        template <class Object>
        class Stack
        {
          public:
            explicit Stack( int capacity = 10 );
            bool isEmpty( ) const;
            .............
        #include "StackAr.cpp"
        #endif

--------------

StackAr.cpp

        #include "StackAr.h"
        template <class Object>
        Stack<Object>::Stack( int capacity ) : theArray( capacity )
        {
            topOfStack = -1;
        }

         template <class Object>
        bool Stack<Object>::isEmpty( ) const
        {
            return topOfStack == -1;
        }
...........

Test.cpp
#include <iostream>
#include "StackAr.h"
using namespace std;

int main()
{
    Stack<int> s;

    for (int i = 0; i < 10; i++)
        s.push(i);

    while (!s.isEmpty())
        cout << s.topAndPop() << endl;
    return 0;
}


---------------------------------------------
error message:

**** Build of configuration Debug for project DACPP ****

make all
Building file: ../src/stack/StackAr.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP 
-MF"src/stack/StackAr.d" -MT"src/stack/StackAr.d" 
-o"src/stack/StackAr.o" "../src/stack/StackAr.cpp"
../src/stack/StackAr.cpp:7: erreur: redefinition of 
‘Stack<Object>::Stack(int)’
../src/stack/StackAr.cpp:7: erreur: ‘Stack<Object>::Stack(int)’ 
previously declared here
../src/stack/StackAr.cpp:17: erreur: redefinition of ‘bool 
Stack<Object>::isEmpty() const’
../src/stack/StackAr.cpp:17: erreur: ‘bool Stack<Object>::isEmpty() 
const’ previously declared here
...............

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-06-02  6:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-02  6:16 Link error ....redefinition of Alex Luya
2009-06-02  6:34 ` Tim München

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).