Multiple definition

E

Ernesto

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
 
R

Rob Williscroft

Ernesto wrote in
This is the BaseClass declaration:


remove:
class BaseClassArrayList;

template < typename BC > class ArrayList;

remove:
class BaseClassDictionary;

template said:
class BaseClass
{
remove:
BaseClassArrayList* GetElementsArrayList();

ArrayList<BaseClass> *GetElementsArrayList();

remove:
BaseClassDictionary* GetElementsDictionary();

Dictionary said:
};


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

Leor Zolman

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
 
E

Ernesto

Leor Zolman said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top