473,654 Members | 3,107 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 BaseClassArrayL ist;
class BaseClassDictio nary;

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

...
...

BaseClassArrayL ist* GetElementsArra yList();
BaseClassDictio nary* GetElementsDict ionary();
};
The BaseClassArrayL ist and the BaseClassDictio nary are instantiations
of class templates:
(A). typedef ArrayList<BaseC lass> BaseClassArrayL ist;

(B). typedef Dictionary<Stri ng, BaseClass> BaseClassDictio nary;
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 BaseClassDictio nary class has been already
defined with "different basic types" (because I added a "class
BaseClassDictio nary;" 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 1860
Ernesto wrote in news:f7******** *************** ***@posting.goo gle.com:

This is the BaseClass declaration:


remove: class BaseClassArrayL ist;
template < typename BC > class ArrayList;

remove: class BaseClassDictio nary;
template < typename S, typename BC > class Dictionary;

class BaseClass
{ ...
remove: BaseClassArrayL ist* GetElementsArra yList();
ArrayList<BaseC lass> *GetElementsArr ayList();

remove: BaseClassDictio nary* GetElementsDict ionary();
Dictionary<Stri ng, BaseClass> * GetElementsDict ionary();
};
The BaseClassArrayL ist and the BaseClassDictio nary are instantiations
of class templates:
(A). typedef ArrayList<BaseC lass> BaseClassArrayL ist;

(B). typedef Dictionary<Stri ng, BaseClass> BaseClassDictio nary;


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


A) should be an error too. First you say BaseClassArrayL ist 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 BaseClassArrayL ist;
class BaseClassDictio nary;

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();

...
...

BaseClassArrayL ist* GetElementsArra yList();
BaseClassDictio nary* GetElementsDict ionary();
};
The BaseClassArrayL ist and the BaseClassDictio nary are instantiations
of class templates:
(A). typedef ArrayList<BaseC lass> BaseClassArrayL ist;

(B). typedef Dictionary<Stri ng, BaseClass> BaseClassDictio nary;
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 BaseClassDictio nary class has been already
defined with "different basic types" (because I added a "class
BaseClassDicti onary;" 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<typena me>
class ArrayList;

template<typena me, typename>
class Dictionary;

class BaseClass;

typedef ArrayList<BaseC lass> BaseClassArrayL ist;
typedef Dictionary<Stri ng, BaseClass> BaseClassDictio nary;

class BaseClass
{
public:
BaseClass();
virtual ~BaseClass();
// ...
BaseClassArrayL ist* GetElementsArra yList();
BaseClassDictio nary* GetElementsDict ionary();
};
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.co m> 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 BaseClassArrayL ist;
class BaseClassDictio nary;


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.co m> 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 BaseClassArrayL ist;
class BaseClassDictio nary;


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
21056
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
17809
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 select the underlying library by template parameter. Therefore we split up our library in two namespaces: The first one defines namespace-global functions which call the baselibrary functions. These are templatefunctions which some
5
2466
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 variable for the multiple definitions. C++, however, does not permit redefinition of a variable or any other entity for a very definite reason that we will discuss later." Chapter 1. C++ Tutorial. Coronado Enterprises Charles L
9
2785
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. Only when I initialize xxxx to two different values in A.c and B.c respectively do I get a 'multiple definitions' error. I was under the impression that I would get such an error even without initializing xxxx twice, simply because i am (ostensibly)...
60
4903
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 'target' programming community herein) to get some community input and verify (or not) the following two statements. Few programmers (3 to7%) UNDERSTAND 'Strategic Functional Migration
11
22559
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
5276
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 `VAR_2' main.o(.data+0x4): first defined here tools.o(.data+0x8): multiple definition of `VAR_3' main.o(.data+0x8): first defined here tools.o(.data+0xc): multiple definition of `VAR_4'
3
2130
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
2803
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 one specific file of class. I have checked that if there is more than one allocation of storage for identifiers, this error arises. But I don't see where the problem lies. Any suggestions? <code> //ItemType.h #ifndef ItemType_hpp // I was...
6
2413
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 implement all of the functions of tortuga.h main.cpp where I use the functions implemented in tortuga.cpp I create the objetc file without problem. But when I try to compile
0
8375
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8290
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8707
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8482
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8593
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6161
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4149
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.