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 10 2425
"John" <jo*********@yahoo.com> wrote in message
news:c3*************************@posting.google.co m... 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.
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.
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::vector
using namespace std
vector //refers to std::vector
-JKop jo*********@yahoo.com (John) wrote in message news:<c3*************************@posting.google.c om>... 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
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::vector or anything else?
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:153:
`vector' is not a template type
/usr/lib/gcc-lib/i386-linux/2.95.4/../../../../include/g++-3/stl_vector.h:154:
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:156:
invalid member template declaration `vector::_Base'
/usr/lib/gcc-lib/i386-linux/2.95.4/../../../../include/g++-3/stl_vector.h:158:
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.
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.
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::vector 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
"ThirdPartySourceCode.cpp", and put the following into it:
namespeace ThirdParty
{
using namespace ThirdParty;
#include <thirdparty.cpp>
}
-JKop
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.hpp ThirdParty.cpp
No, that's too easy. Instead there is
ThirdParty.hpp
ThirdParty.lib
David Harmon posted: 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.hpp ThirdParty.cpp
No, that's too easy. Instead there is
ThirdParty.hpp ThirdParty.lib
Library files are the devil!
-JKop This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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"...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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...
|
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,...
|
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...
| |