473,320 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 4231
dean <de*********@yahoo.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*********@yahoo.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*********@yahoo.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*********@yahoo.comwrote in message news:11*********************@b28g2000cwb.googlegro ups.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*********@yahoo.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*********@yahoo.comwrote:
Rolf Magnus wrote:
>Jakob Bieling wrote:
>>dean <de*********@yahoo.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 misunderstanding 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.com/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.com/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::MyFunc or CMyNamespace::MyFunc.

Dean

Rolf Magnus wrote:
Jakob Bieling wrote:
dean <de*********@yahoo.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
Fred - that is a very good idea. Nice implementation hiding.

Thanks

Dean

Fred Zwarts wrote:
"dean" <de*********@yahoo.comwrote in message news:11*********************@b28g2000cwb.googlegro ups.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*********@yahoo.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 #11
dean wrote [top posting corrected]
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.com/c++-faq-lite/how-to-post.html>
I have no idea what to top-post means.
Top posting is to put your answer above the text that you are replying to.
It is frowned upon in this news group -- that's a cultural thing.

And anyway, what are you adding to this discussion?
E.g., that you might benefit from reading the FAQ (generally a good idea and
part of netiquette).
Best

Kai-Uwe Bux
Sep 15 '06 #12
Gosh! Clearly this is a very important issue for some people so I
apologise to them. I was replying to two people at the same time, not
just one - both of them had good responses. Should I have just quoted
one of them?

Kai-Uwe Bux wrote:
dean wrote [top posting corrected]
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.com/c++-faq-lite/how-to-post.html>
I have no idea what to top-post means.

Top posting is to put your answer above the text that you are replying to.
It is frowned upon in this news group -- that's a cultural thing.

And anyway, what are you adding to this discussion?

E.g., that you might benefit from reading the FAQ (generally a good idea and
part of netiquette).
Best

Kai-Uwe Bux
Sep 15 '06 #13
dean wrote:
I have no idea what to top-post means.
1. I explained it. Here it is again: Your replies belong following or
interspersed with properly trimmed quotes.

2. The FAQ goes over it as well. Did you read it?
And anyway, what are you adding to this discussion?
I'm helping you to get help by posting correctly. It so happens that
I've automated things a bit, so it's easy for me to quickly post the
information. I do that so others don't.


Brian
Sep 15 '06 #14

dean wrote:
Gosh! Clearly this is a very important issue for some people so I
apologise to them.
Usually when you want to apologise to someone you don't do the thing
you are apologising for at the same time; makes you appear inconcere.
If you aren't sorry then don't apologise (many here will end up
killfiling you) and if you are sorry then you won't do it again and
you'll try to learn how to communicate in the group effectively.
You've been given the resources to learn and now know that yes, this is
an important issue. Now you'll either stop top-posting or you won't.
You're decision will have an impact on how people percieve you in the
group and the quality and quantity of answers you recieve.

Sep 15 '06 #15

Default User wrote:
1. I explained it. Here it is again: Your replies belong following or
interspersed with properly trimmed quotes.

2. The FAQ goes over it as well. Did you read it?
And anyway, what are you adding to this discussion?

I'm helping you to get help by posting correctly. It so happens that
I've automated things a bit, so it's easy for me to quickly post the
information. I do that so others don't.

Brian
I already told you I replied to two people, not one. I assumed some
degree of intelligence to follow the discussion flow. Anyway, I got the
best solution from someone who was more interested in the topic than in
correcting other's thread etiquette.

Dean

Sep 15 '06 #16
dean wrote:
Gosh! Clearly this is a very important issue for some people so I
apologise to them. I was replying to two people at the same time, not
just one - both of them had good responses. Should I have just quoted
one of them?
[snip]
Reply to each of them separately. Quote enough material so that your answer
has enough context to be understood. Don't top-post. Just apply some common
sense taking into account the technicalities of news groups as a medium:
different posting propagate with different speeds through the news server
network. Thus, you cannot assume that the readers of your post have its
history nicely aligned above it. Instead you have to provide the context
for your answer. To make clear what your reply refers to, put your reply
below the quote. This way, references are always clear even if you address
several points of the posting that you are answering.
Best

Kai-Uwe Bux
Sep 15 '06 #17
dean wrote:
>
Default User wrote:
1. I explained it. Here it is again: Your replies belong following
or interspersed with properly trimmed quotes.

2. The FAQ goes over it as well. Did you read it?
And anyway, what are you adding to this discussion?
I'm helping you to get help by posting correctly. It so happens that
I've automated things a bit, so it's easy for me to quickly post the
information. I do that so others don't.
I already told you I replied to two people, not one. I assumed some
degree of intelligence to follow the discussion flow. Anyway, I got
the best solution from someone who was more interested in the topic
than in correcting other's thread etiquette.

Say what? That's non-responsive to what I said.

At any rate, trimmed and bottom-posted, so progress I suppose.

Brian

Sep 15 '06 #18

Default User wrote:
dean wrote:

Default User wrote:
1. I explained it. Here it is again: Your replies belong following
or interspersed with properly trimmed quotes.
>
2. The FAQ goes over it as well. Did you read it?
>
And anyway, what are you adding to this discussion?
>
I'm helping you to get help by posting correctly. It so happens that
I've automated things a bit, so it's easy for me to quickly post the
information. I do that so others don't.
I already told you I replied to two people, not one. I assumed some
degree of intelligence to follow the discussion flow. Anyway, I got
the best solution from someone who was more interested in the topic
than in correcting other's thread etiquette.


Say what? That's non-responsive to what I said.

At any rate, trimmed and bottom-posted, so progress I suppose.

Brian
I'd be interested in your opinion on the subject, if you have one
Brian. If not, then please just don't read the thread if it annoys you.

Sep 16 '06 #19

Kai-Uwe Bux wrote:
Reply to each of them separately. Quote enough material so that your answer
has enough context to be understood. Don't top-post. Just apply some common
sense taking into account the technicalities of news groups as a medium:
different posting propagate with different speeds through the news server
network. Thus, you cannot assume that the readers of your post have its
history nicely aligned above it. Instead you have to provide the context
for your answer. To make clear what your reply refers to, put your reply
below the quote. This way, references are always clear even if you address
several points of the posting that you are answering.
Ok. Thanks for being polite.

Can I ask how you're reading this? For me I just go to "google groups"
(http://groups.google.com/group/comp.lang.c++?hl=en) and it gives a
fairly simple tree view on the left, I don't generally have any trouble
seeing how the flow goes, because its neat and tidy and all the old
post text is hidden, is that not the case for you? It seems like it
must be worse for some people here considering the responses.

Dean

Sep 16 '06 #20
dean wrote:
[snip]
Can I ask how you're reading this? For me I just go to "google groups"
(http://groups.google.com/group/comp.lang.c++?hl=en) and it gives a
fairly simple tree view on the left, I don't generally have any trouble
seeing how the flow goes, because its neat and tidy and all the old
post text is hidden, is that not the case for you?
Nope, it is not the case for me: I use a news reader. That program shows me
a threaded list of postings available from the news server, i.e., posts
that have been deleted from the server disappear from my list as well
(Google keeps the complete archive since they got it from DejaNews,
however, most news servers don't). When I select a post, the program
displays that posting only and it does not hide any quoted material (which
is a good thing since the quotes are the only context that is readily
available).

It seems like it must be worse for some people here considering the
responses.
It's actually not worse or better; it's different. It happens to be the way
news groups worked for a few decades (before Google invaded this territory)
and posting styles have adjusted to the media. Personally, I find the
Google interface wanting since it hides the quotations by default. However,
I admit that this is probably a matter of what I am used to.
Best

Kai-Uwe Bux
Sep 16 '06 #21

Kai-Uwe Bux wrote:
Nope, it is not the case for me: I use a news reader. That program shows me
a threaded list of postings available from the news server, i.e., posts
that have been deleted from the server disappear from my list as well
(Google keeps the complete archive since they got it from DejaNews,
however, most news servers don't). When I select a post, the program
displays that posting only and it does not hide any quoted material (which
is a good thing since the quotes are the only context that is readily
available).
[snip]
>
Best

Kai-Uwe Bux
I tried a couple of news-readers once, and I didn't like them at all.
The good thing about google is that you can search all news groups and
get an answer fast, which is really important if you are working.

Thanks for the hints,

Dean

Sep 16 '06 #22

"Default User" <de***********@yahoo.comwrote in message news:4n************@individual.net...
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.com/c++-faq-lite/how-to-post.html>
If you are so concerned that others use Netikette, please,
adhere to Netikette yourself. This newsgroup is about C++,
not about Netikette. If you want to talk about Netikette,
please, use other newsgroups, or use private Email.

Fred.Zwarts.
Sep 18 '06 #23

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

Similar topics

4
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:...
0
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...
5
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...
14
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
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...
16
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...
4
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...
5
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
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,...
6
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.