Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Multiple definition

Reply
Thread Tools

Multiple definition

 
 
Ernesto
Guest
Posts: n/a
 
      04-02-2004
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
 
Reply With Quote
 
 
 
 
Rob Williscroft
Guest
Posts: n/a
 
      04-02-2004
Ernesto wrote in news:(E-Mail Removed) om:

>
> 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/
 
Reply With Quote
 
 
 
 
Leor Zolman
Guest
Posts: n/a
 
      04-02-2004
On 2 Apr 2004 07:46:43 -0800, http://www.velocityreviews.com/forums/(E-Mail Removed) (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
 
Reply With Quote
 
Ernesto
Guest
Posts: n/a
 
      04-07-2004
Leor Zolman <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>. ..
> On 2 Apr 2004 07:46:43 -0800, (E-Mail Removed) (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 I modified my code
following your hints and it compiles perfectly.


Thanks a lot again!!


Saludos



Ernesto
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run-time template list definition / Run-time variable type definition Pierre Yves C++ 2 01-10-2008 02:52 PM
How to avoid multiple definition of a variable by multiple inclusion of a header file lars.uffmann@rwth-aachen.de C++ 11 08-05-2006 10:24 PM
Automagic determination of definition based on definition location. Jon Slaughter C++ 4 10-26-2005 05:00 PM
can a class definition inside another class's definition Jianli Shen C++ 1 03-13-2005 06:02 PM
help?: incomplete definition with complete definition in scope Ark C Programming 1 08-07-2004 04:21 PM



Advertisments