Multiple definition

Discussion in 'C++' started by Ernesto, Apr 2, 2004.

  1. Ernesto

    Ernesto Guest

    Hi everybody:

    I have a strange problem.

    I'm creating a base class BaseClass that contains several methods that
    will be inherited to all the subclasses I will implement.

    This is the BaseClass declaration:


    class BaseClassArrayList;
    class BaseClassDictionary;

    class BaseClass
    {
    public:
    BaseClass();
    virtual ~BaseClass();

    ...
    ...

    BaseClassArrayList* GetElementsArrayList();
    BaseClassDictionary* GetElementsDictionary();
    };


    The BaseClassArrayList and the BaseClassDictionary are instantiations
    of class templates:


    (A). typedef ArrayList<BaseClass> BaseClassArrayList;

    (B). typedef Dictionary<String, BaseClass> BaseClassDictionary;


    The ArrayList and the Dictionary template classes are inherited from
    BaseClass:

    template <class TYPE_T>
    class ArrayList : public BaseClass
    {
    ...
    };


    I'm compiling this code using VS.NET.

    The issue is that when I compile my code, the compiler raises an error
    on (B)saying that the BaseClassDictionary class has been already
    defined with "different basic types" (because I added a "class
    BaseClassDictionary;" on my BaseClass definition), but the error is
    not raised on (A).
    Why cannot I compile this?

    Thanks in advance


    Ernesto
    Ernesto, Apr 2, 2004
    #1
    1. Advertising

  2. Ernesto wrote in news::

    >
    > This is the BaseClass declaration:
    >
    >


    remove:
    > class BaseClassArrayList;


    template < typename BC > class ArrayList;

    remove:
    > class BaseClassDictionary;


    template < typename S, typename BC > class Dictionary;

    >
    > class BaseClass
    > {


    > ...
    >

    remove:
    > BaseClassArrayList* GetElementsArrayList();


    ArrayList<BaseClass> *GetElementsArrayList();

    remove:
    > BaseClassDictionary* GetElementsDictionary();


    Dictionary<String, BaseClass> * GetElementsDictionary();

    > };
    >
    >
    > The BaseClassArrayList and the BaseClassDictionary are instantiations
    > of class templates:
    >
    >
    > (A). typedef ArrayList<BaseClass> BaseClassArrayList;
    >
    > (B). typedef Dictionary<String, BaseClass> BaseClassDictionary;
    >
    >


    >
    > The issue is that when I compile my code, the compiler raises an error
    > on (B)saying that the BaseClassDictionary class has been already
    > defined with "different basic types" (because I added a "class
    > BaseClassDictionary;" on my BaseClass definition), but the error is
    > not raised on (A).


    A) should be an error too. First you say BaseClassArrayList is a class
    then you say its a typedef.


    Rob.
    --
    http://www.victim-prime.dsl.pipex.com/
    Rob Williscroft, Apr 2, 2004
    #2
    1. Advertising

  3. Ernesto

    Leor Zolman Guest

    On 2 Apr 2004 07:46:43 -0800, (Ernesto) wrote:

    >Hi everybody:
    >
    >I have a strange problem.
    >
    >I'm creating a base class BaseClass that contains several methods that
    >will be inherited to all the subclasses I will implement.
    >
    >This is the BaseClass declaration:
    >
    >
    >class BaseClassArrayList;
    >class BaseClassDictionary;
    >


    Those lines above are lies; you mean for them to be specializations of
    templates, not just simple class names; this, and some ordering issues,
    seem to be the problems.

    >class BaseClass
    >{
    > public:
    > BaseClass();
    > virtual ~BaseClass();
    >
    > ...
    > ...
    >
    > BaseClassArrayList* GetElementsArrayList();
    > BaseClassDictionary* GetElementsDictionary();
    >};
    >
    >
    >The BaseClassArrayList and the BaseClassDictionary are instantiations
    >of class templates:
    >
    >
    >(A). typedef ArrayList<BaseClass> BaseClassArrayList;
    >
    >(B). typedef Dictionary<String, BaseClass> BaseClassDictionary;
    >
    >
    >The ArrayList and the Dictionary template classes are inherited from
    >BaseClass:
    >
    >template <class TYPE_T>
    >class ArrayList : public BaseClass
    >{
    > ...
    >};
    >
    >
    >I'm compiling this code using VS.NET.
    >
    >The issue is that when I compile my code, the compiler raises an error
    >on (B)saying that the BaseClassDictionary class has been already
    >defined with "different basic types" (because I added a "class
    >BaseClassDictionary;" on my BaseClass definition), but the error is
    >not raised on (A).
    >Why cannot I compile this?
    >
    >Thanks in advance
    >
    >
    >Ernesto


    Try it this way:

    typedef int String; // dummy typedef for testing

    template<typename>
    class ArrayList;

    template<typename, typename>
    class Dictionary;

    class BaseClass;

    typedef ArrayList<BaseClass> BaseClassArrayList;
    typedef Dictionary<String, BaseClass> BaseClassDictionary;

    class BaseClass
    {
    public:
    BaseClass();
    virtual ~BaseClass();
    // ...
    BaseClassArrayList* GetElementsArrayList();
    BaseClassDictionary* GetElementsDictionary();
    };


    template <class TYPE_T>
    class ArrayList : public BaseClass
    {
    // ...
    };

    int main()
    {
    return 0;
    }


    -leor

    --
    Leor Zolman --- BD Software --- www.bdsoft.com
    On-Site Training in C/C++, Java, Perl and Unix
    C++ users: Download BD Software's free STL Error Message Decryptor at:
    www.bdsoft.com/tools/stlfilt.html
    Leor Zolman, Apr 2, 2004
    #3
  4. Ernesto

    Ernesto Guest

    Leor Zolman <> wrote in message news:<>...
    > On 2 Apr 2004 07:46:43 -0800, (Ernesto) wrote:
    >
    > >Hi everybody:
    > >
    > >I have a strange problem.
    > >
    > >I'm creating a base class BaseClass that contains several methods that
    > >will be inherited to all the subclasses I will implement.
    > >
    > >This is the BaseClass declaration:
    > >
    > >
    > >class BaseClassArrayList;
    > >class BaseClassDictionary;
    > >

    >
    > Those lines above are lies; you mean for them to be specializations of
    > templates, not just simple class names; this, and some ordering issues,
    > seem to be the problems.


    Leor:

    You are right; the lines above were lies :D I modified my code
    following your hints and it compiles perfectly.


    Thanks a lot again!!


    Saludos



    Ernesto
    Ernesto, Apr 7, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jianli Shen
    Replies:
    1
    Views:
    587
    Victor Bazarov
    Mar 13, 2005
  2. Ark
    Replies:
    1
    Views:
    415
    Chris Torek
    Aug 7, 2004
  3. Jon Slaughter
    Replies:
    4
    Views:
    448
    Jon Slaughter
    Oct 26, 2005
  4. Replies:
    11
    Views:
    1,235
    Ian Collins
    Aug 5, 2006
  5. Pierre Yves
    Replies:
    2
    Views:
    481
    Pierre Yves
    Jan 10, 2008
Loading...

Share This Page