public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alex Luya <alex_luya@yeah.net>
To: GCC <gcc@gcc.gnu.org>, GCC-Help <gcc-help@gcc.gnu.org>
Subject: Link error ....redefinition of......
Date: Tue, 02 Jun 2009 06:16:00 -0000	[thread overview]
Message-ID: <4A24C3C3.4030208@yeah.net> (raw)

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
...............

             reply	other threads:[~2009-06-02  6:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-02  6:16 Alex Luya [this message]
2009-06-02  6:34 ` Tim München

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A24C3C3.4030208@yeah.net \
    --to=alex_luya@yeah.net \
    --cc=gcc-help@gcc.gnu.org \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).