473,789 Members | 3,096 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

namespace question

Hi all:

I am using a code from third party. I write my own part and add it to
that code and compile together.
I try to use "vector" in my program. So I add "#include <vector>" to
my program.
But when I compile my program together with the code from the third
party,
the compiler reports error: redefinition of `class vector'.

I look at the code from the third party and find that in one file of
that code,
"class vector" is defined for other purpose.
I can not modify the code from the third party, because it may make
the situation worse.
What should I do to my own program to solve the name confliction
problem?

Thanks a lot.

John
Jul 22 '05 #1
10 2465

"John" <jo*********@ya hoo.com> wrote in message
news:c3******** *************** **@posting.goog le.com...
Hi all:

I am using a code from third party. I write my own part and add it to
that code and compile together.
I try to use "vector" in my program. So I add "#include <vector>" to
my program.
But when I compile my program together with the code from the third
party,
the compiler reports error: redefinition of `class vector'.

I look at the code from the third party and find that in one file of
that code,
"class vector" is defined for other purpose.
I can not modify the code from the third party, because it may make
the situation worse.
What should I do to my own program to solve the name confliction
problem?


Don't write using namesapce std; in your code. You will need to refer to the
standard vector class as std::vector then.
Jul 22 '05 #2
John wrote:
Hi all:

I am using a code from third party. I write my own part and add it to
that code and compile together.
I try to use "vector" in my program. So I add "#include <vector>" to
my program.
But when I compile my program together with the code from the third
party, the compiler reports error: redefinition of `class vector'.

I look at the code from the third party and find that in one file of
that code, "class vector" is defined for other purpose.
I can not modify the code from the third party, because it may make
the situation worse.
What should I do to my own program to solve the name confliction
problem?


The C++ standard class vector is in namespace std, so unless your 3rd
party library puts it there, too, there shouldn't be a name conflict.
After all, that's why namespaces exist.
If your compiler doesn't put vector into namespace std, then it is
probably quite outdated and you should consider using a more recent
one.

Jul 22 '05 #3
John posted:
Hi all:

I am using a code from third party. I write my own part and add it to
that code and compile together.
I try to use "vector" in my program. So I add "#include <vector>" to
my program.
But when I compile my program together with the code from the third
party,
the compiler reports error: redefinition of `class vector'.

I look at the code from the third party and find that in one file of
that code,
"class vector" is defined for other purpose.
I can not modify the code from the third party, because it may make
the situation worse.
What should I do to my own program to solve the name confliction
problem?

Thanks a lot.

John

namespace ThirdParty
{

#include <thirdpary>
}
std::vector
ThirdParty::vec tor
using namespace std
vector //refers to std::vector

-JKop
Jul 22 '05 #4
jo*********@yah oo.com (John) wrote in message news:<c3******* *************** ***@posting.goo gle.com>...
Hi all:

I am using a code from third party. I write my own part and add it to
that code and compile together.
I try to use "vector" in my program. So I add "#include <vector>" to
my program.
But when I compile my program together with the code from the third
party,
the compiler reports error: redefinition of `class vector'.

I look at the code from the third party and find that in one file of
that code,
"class vector" is defined for other purpose.
I can not modify the code from the third party, because it may make
the situation worse.
What should I do to my own program to solve the name confliction
problem?
Well, the vector template that is defined in <vector> resides in
namespace std, so you should still be able to use it even in the
presence of the other vector class by specifying std::vector instead
of just vector. Note also that getting rid of using directives (e.g.
using namespace std) is generally a good idea, and will help identify
more name collisions between std::vector and your vendors' vector as
well.

HTH, Dave Moore
Thanks a lot.

John

Jul 22 '05 #5
On Wed, 02 Jun 2004 12:32:50 GMT in comp.lang.c++, JKop <NU**@NULL.NULL >
wrote,
namespace ThirdParty
{

#include <thirdpary>
}


You think so, huh? Where is the linker going to find the definition of
ThirdParty::vec tor or anything else?

Jul 22 '05 #6
Hi all:

Thanks for reply.
In my program, I already use std::vector except the line: #include
<vector>.
Below is part of the error message:
In file included from
/usr/lib/gcc-lib/i386-linux/2.95.4/../../../../include/g++-3/vector.h:32,
from mycode.cc:35:
/usr/lib/gcc-lib/i386-linux/2.95.4/../../../../include/g++-3/stl_vector.h:15 3:
`vector' is not a template type
/usr/lib/gcc-lib/i386-linux/2.95.4/../../../../include/g++-3/stl_vector.h:15 4:
redefinition of `class vector'
mobile/god.h:117: previous definition here
/usr/lib/gcc-lib/i386-linux/2.95.4/../../../../include/g++-3/stl_vector.h:15 6:
invalid member template declaration `vector::_Base'
/usr/lib/gcc-lib/i386-linux/2.95.4/../../../../include/g++-3/stl_vector.h:15 8:
invalid member template declaration `vector::value_ type'

mycode.cc is my own code. Line 35 is #include <vector>. mobile/god.h
is the code
from third party.
I also use list in my code, the compiler does not complain it.

Thanks a lot.

John

Rolf Magnus <ra******@t-online.de> wrote in message news:<c9******* ******@news.t-online.com>...
John wrote:
Hi all:

I am using a code from third party. I write my own part and add it to
that code and compile together.
I try to use "vector" in my program. So I add "#include <vector>" to
my program.
But when I compile my program together with the code from the third
party, the compiler reports error: redefinition of `class vector'.

I look at the code from the third party and find that in one file of
that code, "class vector" is defined for other purpose.
I can not modify the code from the third party, because it may make
the situation worse.
What should I do to my own program to solve the name confliction
problem?


The C++ standard class vector is in namespace std, so unless your 3rd
party library puts it there, too, there shouldn't be a name conflict.
After all, that's why namespaces exist.
If your compiler doesn't put vector into namespace std, then it is
probably quite outdated and you should consider using a more recent
one.

Jul 22 '05 #7
John wrote:
Hi all:

Thanks for reply.
In my program, I already use std::vector except the line: #include
<vector>.
Below is part of the error message:
In file included from
/usr/lib/gcc-lib/i386-linux/2.95.4/../../../../include/g++-3/vector.h:32,

^^^^^^
This is your problem. The compiler is too old. g++ versions before 3.x
are not compliant wrt namespace std. They make std a synonym for the
global namespace. If possible, you should upgrade to gcc 3.x.

Jul 22 '05 #8
David Harmon posted:
On Wed, 02 Jun 2004 12:32:50 GMT in comp.lang.c++, JKop <NU**@NULL.NULL >
wrote,
namespace ThirdParty {

#include <thirdpary> }


You think so, huh? Where is the linker going to find the definition of
ThirdParty::vec tor or anything else?

Let's assume that there's:
ThirdParty.hpp
ThirdParty.cpp

In the Source Code file in which you wish to use this library, put:

namespace ThirdParty
{
#include <thirdparty.hpp >
}

And now, for the Source code file... Don't actually add it to your project
to be compiled; instead, do this: Make another file
"ThirdPartySour ceCode.cpp", and put the following into it:
namespeace ThirdParty
{

using namespace ThirdParty;

#include <thirdparty.cpp >
}

-JKop
Jul 22 '05 #9
On Wed, 02 Jun 2004 18:16:05 GMT in comp.lang.c++, JKop <NU**@NULL.NULL >
wrote,
Let's assume that there's:
ThirdParty.h pp
ThirdParty.c pp


No, that's too easy. Instead there is

ThirdParty.hpp
ThirdParty.lib

Jul 22 '05 #10

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

Similar topics

1
2725
by: John L. Clark | last post by:
I am curious as to the rationale, and effect, of having default namespaces not applying (directly) to attributes (see http://www.w3.org/TR/REC-xml-names/#defaulting). Given an attribute without a namespace prefix, what is its namespace, if default namespaces do not apply? Are (either of) prefixed or non-prefixed attributes correct? For example, are the following equivalent: <html:br class="foo"...
25
3097
by: kj | last post by:
Consider the following XML document: <?xml version='1.0' encoding='UTF-8'?> <bar:foo xmlns:bar='someuri'> <baz/> </bar:foo> What namespace does baz belong to? What is this namespace bound to/associated with? My understanding was that baz above belongs to some "default default namespace", but I have not been able to
3
10043
by: Mike Dickens | last post by:
hi, i'm sure this has come up before but havn't managed to find an answer. if i have the following xslt <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet method="xml" version="1.0" xmlns:ns1="abc" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes" media-type="text/xml" standalone="yes" version="1.0"/> <xsl:template match="/">
6
555
by: clinton__bill | last post by:
Hi, I usually use "using namespace <namespace_name>" to reference a namespace. Today I run across a code, in its header file it has this, namespace SP1{ class C1; } While SP1::C1 is a namespace::class declared and defined somewhere else. It seems the above 3 lines is similar to "using namespace SP1;",
2
7515
by: Tony Johansson | last post by:
Hello! I'm reading a book about C++ and there is something that I don't understand so I ask you. Below I have the text from the book and the code from the file where main is located and some namespace definition with class definitions. The book says "C++ has a global anonymous namespace that is similar to Java's global anonymous package. All declarations not explicitly placed in named
20
3872
by: Patrick Guio | last post by:
Dear all, I have some problem with insertion operator together with namespace. I have a header file foo.h containing declaration of classes, typedefs and insertion operators for the typedefs in a named namespace namespace foo { class Foo
4
4395
by: Programatix | last post by:
Hi, Normally, I would use Namespace for all the window forms I created. With VS 2005, the code generated by the designer is hidden using partial keyword. The question is, is there an efficient way to add any window forms created into a namespace? Currently, I enclose the class for .vb and .designer.vb inside a namespace manually.
32
30508
by: toolmaster | last post by:
Since many of the modern computer languages have built-in namespace features, I can't understand why not add this feature into standard C. I've heard many people complain of the lacking of namespace in C. Of course, namespace doesn't eliminate name polution, but it helps more than just to put some prefix before a function name. Is it because adding namespace will make C more complex or some other reasons?
3
2288
by: CrazyJohn | last post by:
Hi guys, This is my first time posting question here, if I break any rules, please kindly point out. And I'm really glad to be a part of this community. Here is my question, Our lecturer told us that Unnamed Namespace is an alternative to Static Internal Variables, but he also said that Namespace has an
17
30685
by: Peng Yu | last post by:
Hi, I'm wondering if there is something in namespace like the 'private' keyword in class? I want to define some class or function that can only be used within that namespace. Thanks, Peng
0
9665
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
9511
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
10199
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
10139
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
6768
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4092
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 we have to send another system
2
3697
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.