473,503 Members | 3,171 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple definition

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
Jul 22 '05 #1
4 1846
Ernesto wrote in news:f7**************************@posting.google.c 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/
Jul 22 '05 #2
On 2 Apr 2004 07:46:43 -0800, eb*****@hotmail.com (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
Jul 22 '05 #3
Leor Zolman <le**@bdsoft.com> wrote in message news:<dq********************************@4ax.com>. ..
On 2 Apr 2004 07:46:43 -0800, eb*****@hotmail.com (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
Jul 22 '05 #4
Leor Zolman <le**@bdsoft.com> wrote in message news:<dq********************************@4ax.com>. ..
On 2 Apr 2004 07:46:43 -0800, eb*****@hotmail.com (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
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
21029
by: Jochen Zeischka | last post by:
Hi everybody! I have a question concerning code organisation. Suppose I have the following header file: #ifndef SOME_NAME #define SOME_NAME namespace N { void F()
11
17801
by: Georg Teichtmeister | last post by:
Hello! We are developing a math - library for realtime applications and want to use some given mathlibraries as base(ipp, MTL, .. ). Our library is a wrapper for those and you should be able to...
5
2459
by: Charles L | last post by:
Can someone explain to me what the following means? "C permits multiple definitions of a variable in any given namespace, provided the definitions are the same and it generates only a single...
9
2775
by: lbj137 | last post by:
I have two files: A.c and B.c. In both files I define a global variable, int xxxx; When I compile with a green hills compiler (and also i think with a GNU compiler) I get no errors or warnings....
60
4866
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the...
11
22531
by: lars.uffmann | last post by:
Easily described problem: Using g++ version 3.3.5 under suse 9.3, bla.h: ----------- #ifndef myTEST #define myTEST ZFSInt test; #endif
3
5263
by: Student | last post by:
Hi all, While compiling a program I had this message : tools.o(.data+0x0): multiple definition of `VAR_1' main.o(.data+0x0): first defined here tools.o(.data+0x4): multiple definition of...
3
2105
by: Jens Müller | last post by:
I have a file here with several enums: #ifndef PLANARSEP_OPTIMIZE_H #define PLANARSEP_OPTIMIZE_H enum fund_cycle_behavior_t {PASS_MODE_FIRST, PASS_MODE_BEST, PASS_MODE_ALL};
10
2789
by: zfareed | last post by:
Similar problem to the previous post. I have created a project with about 7 files including 3 header files and 3 implementation files. I am getting a multiple definition error when compiling for...
6
2401
by: Gaijinco | last post by:
I'm having a weird error compiling a multiple file project: I have three files: tortuga.h where I have declared 5 global variables and prototypes for some functions. tortuga.cpp where I...
0
7188
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7258
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7313
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6970
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4987
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3156
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1489
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
366
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.