473,769 Members | 6,286 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

namespace and #include

I want to add some declaration intio my namespace. But I do not have
the right to modify proto header files.
So I try
namespace mynamespace{
#include "a.h"
#include "b.h"
}

This is not a good style. But it even cannot work..... functions in
a.h has NOT been put into mynamespace....
Sep 24 '08 #1
4 2145
On Sep 24, 7:35*am, Hua.wat...@gmai l.com wrote:
I want to add some declaration intio my namespace. But I do not have
the right to modify proto header files.
So I try

namespace mynamespace{
#include "a.h"
#include "b.h"

}

This is not a good style. But it even cannot work..... functions in
a.h has NOT been put into mynamespace....
This should help you solve your problems with migrating to namespace:
http://www.gotw.ca/gotw/053.htm
Sep 24 '08 #2
On Sep 24, 7:35*pm, Hua.wat...@gmai l.com wrote:
I want to add some declaration intio my namespace. But I do not have
the right to modify proto header files.
So I try

namespace mynamespace{
#include "a.h"
#include "b.h"

}

This is not a good style. But it even cannot work..... functions in
a.h has NOT been put into mynamespace....
you also need to put the definition into your new namespace.

I guess you forgot to wrap your cxx files with your namespace.
suppose you have a.cpp corresponding to a.h, whereas b.cpp for a.h

use wrappers like a_wrap.cpp as following, and do remember to have
header
inclusion guard.

suppose A_H_INCLUDED for a.h

#include "a.h" // A_H_INCLUDED is define here

namespace mynamespace {
#include "a.cpp" // preprocesser #include "a.h" in a.cpp will be
discarded
}

exclude a.cpp in your project. while a_wrap.cpp is included

HTH.

--
Best Regards
Barry
Sep 24 '08 #3
On Sep 24, 7:35*pm, Hua.wat...@gmai l.com wrote:
I want to add some declaration intio my namespace. But I do not have
the right to modify proto header files.
So I try

namespace mynamespace{
#include "a.h"
#include "b.h"

}

This is not a good style. But it even cannot work..... functions in
a.h has NOT been put into mynamespace....
you need to put the definition into your namespace

I guess you forgot to wrap your cxx files into you namespace
suppose you have a.cpp for a.h

remember to have header inclusion guard
suppose A_H_INCLUDED for a.h

so write your a_wrap.cpp like this:

#include "a.h" // A_H_INCLUDED is defined

namespace mynamespace {
#include "a.cpp" // a.h in a.cpp will be discarded
}
HTH.

--
Best Regards
Barry
Sep 24 '08 #4
On 9ÔÂ24ÈÕ, ÏÂÎç10ʱ20·Ö, Barry <dhb2...@gmail. com>wrote:
On Sep 24, 7:35 pm, Hua.wat...@gmai l.com wrote:
I want to add some declaration intio my namespace. But I do not have
the right to modify proto header files.
So I try
namespace mynamespace{
#include "a.h"
#include "b.h"
}
This is not a good style. But it even cannot work..... functions in
a.h has NOT been put into mynamespace....

you need to put the definition into your namespace

I guess you forgot to wrap your cxx files into you namespace
suppose you have a.cpp for a.h

remember to have header inclusion guard
suppose A_H_INCLUDED for a.h

so write your a_wrap.cpp like this:

#include "a.h" // A_H_INCLUDED is defined

namespace mynamespace {
#include "a.cpp" // a.h in a.cpp will be discarded

}

HTH.

--
Best Regards
Barry
Thanks, my code is like:

In global.h:
typedef int int32_t;
enum{ENUM_A};

In someone.h:
enum{ENUM_A};

In my.h:
namespace myspace{
#include "a.h"
}

In my.cpp
#include "global.h"
#include "someone.h"

myspace::int32_ t ........

Then compiler tell me 2 error
1. ENUM_A conflict
2. int32_t is not in namespace myspace

In fact, I need include both global.h and someone.h to use some
functions, however, they defined some same unnamed enum. Now I have to
use 2 cpp file.....

Thanks
Sep 25 '08 #5

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

Similar topics

2
5695
by: Anonymous | last post by:
How do I reference a namespace variable in a multi-file project? Do I use the keyword 'extern'? If so, does the word 'extern' modify the namespace or the individual variables within the namespace? For example, suppose I have the following 3 files: -----------------------//myns.h #include <iostream> using namespace std;
2
2495
by: Stanimir Stamenkov | last post by:
I'm trying to find out if it is permissible to include a schema document with absent target namespace to a schema with specified target namespace, and if it is, what are the rules to resolve the target namespace of the components from the included schema document. I'm confused because of the rules I read in the XML Schema spec <http://www.w3.org/TR/xmlschema-1/#element-element>: > If the <element> element information item has <schema>...
7
3483
by: zbyszek | last post by:
I am working with a large C++ program which, for reasons of backward compatibility, uses C's printf and fprintf rather than iostreams. For a certain type of build I want to provide new functions that change the behaviour of printf and fprintf, and I planned to make them available using a convenient namespace, called 'herring', say, like this: using herring::printf; using herring::fprintf;
5
5717
by: Enos Meroka | last post by:
Hallo, I am a student doing my project in the university.. I have been trying to compile the program using HP -UX aCC compiler, however I keep on getting the following errors. ================================================================= Error 19: "CORBAManagerMessages.h", line 4 # Unexpected 'std'. using std::string; ^^^
2
5618
by: puzzlecracker | last post by:
after reading some of the post I found out something rather radical to my previous understanding: that when you do #include<iostream> #include<string> #include<vector> etc compiler puts those .h files into the namespace std -.h files that contain all the declarations for vector, string, etc...
12
3384
by: Calum Grant | last post by:
In older C++ computer books, you'll often see using namespace std; even in my 1996 copy of Stroustrup. Nowadays, it seems to be considered better to qualify names to make it clearer what symbol you are using. Are there any articles that support this viewpoint? Is "using namespace" definitively wrong, or just a matter of style? How about when implementing a library "foo", would it not make the code
4
3083
by: Kevin Newman | last post by:
The primary problem I've had with php is the lack of namespaces, which makes OOP very difficult to organize, since you end up with large number of classes cluttering up the same namespace - which leads to a secondary problem involving php's __autoload feature. Since you cannot specify a namespace when calling a class that may not have been included, you are forced to store all of your classes in the same folder in your file system. This...
14
6704
by: Jon Rea | last post by:
I am currently cleaning up an application which was origainlly hashed together with speed of coding in mind and therefore contains quite a few "hacky" shortcuts. As part of this "revamping" process I am introducing namespaces to properly compartmentalise sections of the code into logical units. What I am speciffically trying to get right is the dependency tree for header files to reduce compile time and simplify the code structure. On...
1
5418
by: toton | last post by:
Hi, I have two namespace contains class InkFrame and PrefDialog respectively. PrefDialog needs InkFrame to show the dialog over the frame. It also stores a pointer to InkFrame inside it. Now I want InkFrame to be forward declared in the PrefDialog header file rather than to be included. I want to include it in the cpp file instead. There is no harm including it in PrefDialog header, and it works. But I want to save some compilation time....
5
1450
by: michael.d.pedersen | last post by:
Hello group, I am new to Visual C++ 8 and have a seemingly trivial problem using namespaces. The scenario: I have two classes, TestClass1 and TestClass2, in the namespace Test. I would like to create a reference to TestClass2 in TestClass1; but the compiler doesn't seem to recognize the namespace Test and any classes in it. Here are my class definitions and declarations:
0
9587
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...
1
9993
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
9863
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...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
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
6672
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
5298
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...
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.