473,671 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

class vs namespace?

Hi all,

We have a few existing classes that we want to put into either another
class or a namespace, so that we can avoid naming conflicts. As far as
I can see the syntax is identical from a usage perspective.

Does anyone have an opinion on this either way?

Thanks

Dean

Sep 15 '06 #1
22 4254
dean <de*********@ya hoo.comwrote:
Hi all,

We have a few existing classes that we want to put into either another
class or a namespace, so that we can avoid naming conflicts. As far as
I can see the syntax is identical from a usage perspective.

Does anyone have an opinion on this either way?
For your purpose, namespaces are the way to go. You can reopen a
namespace and add stuff across translation units. You cannot do this
with classes. In addition, using a class implies that you can create an
instance of that class, which, as I understood it, is not the case.

hth
--
jb

(reply address in rot13, unscramble first)
Sep 15 '06 #2
Jakob Bieling wrote:
dean <de*********@ya hoo.comwrote:
>Hi all,

We have a few existing classes that we want to put into either another
class or a namespace, so that we can avoid naming conflicts. As far as
I can see the syntax is identical from a usage perspective.

Does anyone have an opinion on this either way?

For your purpose, namespaces are the way to go. You can reopen a
namespace and add stuff across translation units. You cannot do this
with classes. In addition, using a class implies that you can create an
instance of that class, which, as I understood it, is not the case.
Also, you can use using-declarations with namespaces, and AFAIK that's not
possible with classes, at least not if you don't derive from them.

Sep 15 '06 #3
So what to do about member variables of the class, if we use a
namespace instead? I mean, how can one hide a private variable and just
allow accessor (get and set) functions? Put the member variable outside
of the namespace but in the same unit as the namespace?
Rolf Magnus wrote:
Jakob Bieling wrote:
dean <de*********@ya hoo.comwrote:
Hi all,

We have a few existing classes that we want to put into either another
class or a namespace, so that we can avoid naming conflicts. As far as
I can see the syntax is identical from a usage perspective.

Does anyone have an opinion on this either way?
For your purpose, namespaces are the way to go. You can reopen a
namespace and add stuff across translation units. You cannot do this
with classes. In addition, using a class implies that you can create an
instance of that class, which, as I understood it, is not the case.

Also, you can use using-declarations with namespaces, and AFAIK that's not
possible with classes, at least not if you don't derive from them.
Sep 15 '06 #4
"dean" <de*********@ya hoo.comwrote in message news:11******** *************@b 28g2000cwb.goog legroups.com...
So what to do about member variables of the class, if we use a
namespace instead? I mean, how can one hide a private variable and just
allow accessor (get and set) functions? Put the member variable outside
of the namespace but in the same unit as the namespace?
I would think the other way around.
Put the private variable in the same namespace but in another unit
(the unit in which you write the body of the get and set functions).
The advantage above a class implementation is that the private variables
are not even declared in the header file.
The header file discloses nothing about the implementation,
it has only the interface

Fred.Zwarts.
Rolf Magnus wrote:
>Jakob Bieling wrote:
dean <de*********@ya hoo.comwrote:
Hi all,

We have a few existing classes that we want to put into either another
class or a namespace, so that we can avoid naming conflicts. As far as
I can see the syntax is identical from a usage perspective.

Does anyone have an opinion on this either way?

For your purpose, namespaces are the way to go. You can reopen a
namespace and add stuff across translation units. You cannot do this
with classes. In addition, using a class implies that you can create an
instance of that class, which, as I understood it, is not the case.

Also, you can use using-declarations with namespaces, and AFAIK that's not
possible with classes, at least not if you don't derive from them.
Sep 15 '06 #5
dean <de*********@ya hoo.comwrote:
Rolf Magnus wrote:
>Jakob Bieling wrote:
>>dean <de*********@ya hoo.comwrote:
>>>We have a few existing classes that we want to put into either
another class or a namespace, so that we can avoid naming
conflicts. As far as I can see the syntax is identical from a
usage perspective.

Does anyone have an opinion on this either way?
>> For your purpose, namespaces are the way to go. You can reopen a
namespace and add stuff across translation units. You cannot do this
with classes. In addition, using a class implies that you can
create an instance of that class, which, as I understood it, is not
the case.
>Also, you can use using-declarations with namespaces, and AFAIK
that's not possible with classes, at least not if you don't derive
from them.
So what to do about member variables of the class, if we use a
namespace instead? I mean, how can one hide a private variable and
just allow accessor (get and set) functions? Put the member variable
outside of the namespace but in the same unit as the namespace?
I think I am not following. You said you have several classes and
want to put them into a namespace (or class, but let's just stick to the
namespace now) to avoid naming conflicts:

class A { int a; };
class B { int b; };

becomes

namespace dean
{
class A { int a; };
class B { int b; };
};

As you can see, your classes do not change. Their members stay right
where they are. You only introduce a new namespace and put the stuff in
there.

Apologies, if I am misunderstandin g you.

hth
--
jb

(reply address in rot13, unscramble first)
Sep 15 '06 #6
dean wrote:
So what to do about member variables of the class


Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or the group FAQ list:
<http://www.parashift.c om/c++-faq-lite/how-to-post.html>


Brian
Sep 15 '06 #7
I have no idea what to top-post means. And anyway, what are you adding
to this discussion?
Default User wrote:
dean wrote:
So what to do about member variables of the class

Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or the group FAQ list:
<http://www.parashift.c om/c++-faq-lite/how-to-post.html>


Brian
Sep 15 '06 #8

dean wrote:
I have no idea what to top-post means. And anyway, what are you adding
to this discussion?
You need to read the webpage to which you where directed.

Sep 15 '06 #9
Rolf - for better or worse, the company agreed not to use "using
namespace", but rather add the scope prefix onto each member, e.g.
CMyClass::MyFun c or CMyNamespace::M yFunc.

Dean

Rolf Magnus wrote:
Jakob Bieling wrote:
dean <de*********@ya hoo.comwrote:
Hi all,

We have a few existing classes that we want to put into either another
class or a namespace, so that we can avoid naming conflicts. As far as
I can see the syntax is identical from a usage perspective.

Does anyone have an opinion on this either way?
For your purpose, namespaces are the way to go. You can reopen a
namespace and add stuff across translation units. You cannot do this
with classes. In addition, using a class implies that you can create an
instance of that class, which, as I understood it, is not the case.

Also, you can use using-declarations with namespaces, and AFAIK that's not
possible with classes, at least not if you don't derive from them.
Sep 15 '06 #10

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

Similar topics

4
3817
by: marco_segurini | last post by:
Hi, the following test program shows a solution to a problem I have had. Now, this test program is compiled and linked by VS2003 and g++ while Comeau-on-line-compiler fails with this messages: "ComeauTest.c", line 21: error: constant "COuter::ID" is inaccessible int i = COuter::ID; ^
0
3024
by: keith bannister via .NET 247 | last post by:
(Type your message here) -------------------------------- From: keith bannister Hi, I'm new to .net (as of last week) but here goes. I want to serialize/deserialize a file the conforms to an XML schema (xsd).
5
7282
by: Keith Bannister | last post by:
I'm new to .net so here goes. I'm tying to deserialize a class that is associated with an XML schema. I created the C# class with xsd.exe as below: xsd.exe /c /n:somenamespace properties.xsd this creates properties.cs
14
1972
by: Lee Franke | last post by:
I can't seem to figure this one out. Here is my class structure namespace name { public class foo { } }
6
3405
by: ryan.d.rembaum | last post by:
Hello, I have code that I wish to use in many web applications. Basically sort of stand utility stuff. So from Visual Studio Project I select add a component and chose Component Class. Lets say I enter code at the end of this question in to the code section. How then would I reference this in a new Web Application (or in the same web application for that matter?)
16
2361
by: tshad | last post by:
This is a little complicated to explain but I have some web services on a machine that work great. The problem is that I have run into a situation where I need to set up my program to access one or another (could also be 3) different web servers to use these Web Services. The Web Services are identical on all the machines. I tried just changing the URL of the Web Services and cannot make it work. I then decided to create 2 identical web...
4
1693
by: R. Nachtsturm | last post by:
Hi, Question (in short): can i somehow use the namespace tag to define that a class in its own file is actually the subclass (namespace wise) of another class? Explanation: for example, if I have one class named "Schema", this class should have a public sub class named "Table", such as:
5
5479
by: Marcin Gil | last post by:
Hi! I have the code like this (obvious things like ctor/dtor removed) typedef struct _NODE { int val; int index; } Node;
9
6471
by: Mark Olbert | last post by:
I'm trying to serialize (using XmlSerializer.Serialize) a class that I generated from an XSD schema using XSD.EXE /c. The problem I'm running into is that the root element needs to be unqualified, and the default namespace needs to be included on it as an attribute. The schema I'm using is this: <xs:schema xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:html="http://www.w3.org/TR/REC-html40"...
6
369
by: Nikola | last post by:
Is it possible in C++ to create a class hierarchy by inheritance that spans across various namespaces? For example, say I want to create a class which would behave like object type in C#, so that all classes I have would be below it in inheritance hierarchy, but my classes are scattered throughout various namespaces. Say I have 2 classes in namespace A and 2 in namespace B, where namespace A and namespace B are not related, and now I...
0
8474
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
8392
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
8912
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7428
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
6222
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
4222
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...
1
2809
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
2049
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1807
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.