What is the difference between these two situations:
1- hold a namespace which contains justs some functions:
namespace MyNamespace
{
void foo1();
void foo2();
void foo3();
void foo4();
....
}
and
2- hold a class within just a default constructor:
class Myclass
{
public:
Myclass() {};
void foo1();
void foo2();
void foo3();
void foo4();
...
}
Thanks in advance for your answers
Yous! 15 5988
Youssef Mesri wrote: What is the difference between these two situations:
1- hold a namespace which contains justs some functions:
namespace MyNamespace { void foo1(); void foo2(); void foo3(); void foo4(); ...
}
and 2- hold a class within just a default constructor:
class Myclass { public: Myclass() {}; void foo1(); void foo2(); void foo3(); void foo4(); ... ~Myclass() {}; }
Thanks in advance for your answers
Yous!
Youssef Mesri wrote: What is the difference between these two situations:
1- hold a namespace which contains justs some functions:
namespace MyNamespace { void foo1(); void foo2(); void foo3(); void foo4(); ...
}
and 2- hold a class within just a default constructor:
class Myclass { public: Myclass() {}; void foo1(); void foo2(); void foo3(); void foo4(); ...
}
Thanks in advance for your answers
Generally speaking, the difference is that to access thos member functions
of a class, you need an instance of that class. And inside those member
functions the instance is identifiable through the 'this' pointer. The
namespace-based functions do not have the 'this' pointer. They are more
like static members of the class. You could write
class Myclass
{
public:
static void foo1();
static void foo2();
...
};
which would be _very_much_ like those functions in your namespace.
V
Youssef Mesri wrote: What is the difference between these two situations:
1- hold a namespace which contains justs some functions:
[ ... ]
2- hold a class within just a default constructor:
You still have to create an instance of the class to call its member
functions, whereas there's no such thing as an instance of a namespace.
To get something closer to a namespace, your class would have a private
ctor to prevent constructing objects, and the other functions would all
be static so you could call them without referring to an particular
object (since no such object will ever exist).
--
Later,
Jerry.
Jerry Coffin wrote: Youssef Mesri wrote: What is the difference between these two situations:
1- hold a namespace which contains justs some functions:
[ ... ]
2- hold a class within just a default constructor:
You still have to create an instance of the class to call its member functions, whereas there's no such thing as an instance of a namespace.
To get something closer to a namespace, your class would have a private ctor to prevent constructing objects, and the other functions would all be static so you could call them without referring to an particular object (since no such object will ever exist).
As far as I can tell (I don't have my copy of the Standard present), the
differences between a namespace and a class with static only members
would be:
1. You can use a using directive to bring all or part of a namespace
into the current scope.
2. You can extend a namespace (add other members/etc...) without
modifying the existing source.
3. You can mark certain members of the class private or protected.
Victor Bazorov wrote:
[quote]
Generally speaking, the difference is that to access thos member
functions
of a class, you need an instance of that class. And inside those
member
functions the instance is identifiable through the 'this' pointer. The
namespace-based functions do not have the 'this' pointer. They are
more
like static members of the class. You could write
class Myclass
{
public:
static void foo1();
static void foo2();
...
};
which would be _very_much_ like those functions in your namespace.
V
[end of quote]
Indeed it is similar but having them as static members of a class can
actually have an advantage in certain situations.
You can use the class as a template parameter, something you cannot do
with a namespace.
Youssef Mesri wrote: What is the difference between these two situations:
1- hold a namespace which contains justs some functions:
namespace MyNamespace { void foo1(); void foo2(); void foo3(); void foo4(); ...
}
and 2- hold a class within just a default constructor:
class Myclass { public: Myclass() {}; void foo1(); void foo2(); void foo3(); void foo4(); ...
}
Thanks in advance for your answers
Yous!
In addition to what others have said, namespaces are also open, they
can be spread across files. For example you can do this
//file1
namespace Foo
{
void f1() { /* do something */ }
}
// file2
namesapce Foo
{
void f2() { /* do something */ }
}
You can't do this with a class.
> In addition to what others have said, namespaces are also open, they can be spread across files. For example you can do this
//file1 namespace Foo { void f1() { /* do something */ } }
// file2 namesapce Foo { void f2() { /* do something */ } }
You can't do this with a class.
Actually, the separate files aren't the point. You can't do this in
the same file either with a class. But namespaces are open, that was
my point.
red floyd wrote: As far as I can tell (I don't have my copy of the Standard present), the differences between a namespace and a class with static only members would be:
1. You can use a using directive to bring all or part of a namespace into the current scope. 2. You can extend a namespace (add other members/etc...) without modifying the existing source. 3. You can mark certain members of the class private or protected.
4. You can use the class as a template parameter.
BigBrian wrote: Actually, the separate files aren't the point. You can't do this in the same file either with a class. But namespaces are open, that was my point.
Although classes aren't open, there is a workaround which is to define
free functions that take class members as parameters.
In this case it can also be done with a function that takes multiple
overloads (and may or may not have a template version that works by
default).
Of course the free functions only get public access (unless you modify
the header of the class which we've assumed you're not allowed to do)
and must themselves be public (though not necessarily unlimited in
scope as they can be written in an anonymous namespace).
Youssef Mesri wrote: What is the difference between these two situations:
1- hold a namespace which contains justs some functions:
namespace MyNamespace { void foo1(); void foo2(); void foo3(); void foo4(); ...
}
and 2- hold a class within just a default constructor:
class Myclass { public: Myclass() {}; void foo1(); void foo2(); void foo3(); void foo4(); ...
}
Thanks in advance for your answers
Yous!
In addition to what others have said, namespaces are also open, they
can be spread across files. For example you can do this
//file1
namespace Foo
{
void f1() { /* do something */ }
}
// file2
namesapce Foo
{
void f2() { /* do something */ }
}
You can't do this with a class.
Earl Purple wrote: Victor Bazorov wrote: [quote]
[end of quote]
This would be more readable if you used the actual Google quoting
mechanism. See .sig below.
Brian
--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
Default User wrote: Earl Purple wrote:
Victor Bazorov wrote: [quote]
[end of quote]
This would be more readable if you used the actual Google quoting mechanism. See .sig below. Brian
-- Please quote enough of the previous message for context. To do so from Google, click "show options" and use the Reply shown in the expanded header.
I know what to do was waiting a lifetime for the form to come up. I
blame the programmers - obviously it wasn't written in standard C++.
On 18 Jan 2006 11:59:35 -0800, "Earl Purple" <ea********@gmail.com>
wrote: Please quote enough of the previous message for context. To do so from Google, click "show options" and use the Reply shown in the expanded header. I know what to do was waiting a lifetime for the form to come up. I blame the programmers - obviously it wasn't written in standard C++.
You don't have to use Google. http://www.forteinc.com/main/homepage.php
They have a free version that is very good.
--
Solitary trees, if they grow at all, grow strong.
Winston Churchill
Earl Purple wrote: Default User wrote: Please quote enough of the previous message for context. To do so from Google, click "show options" and use the Reply shown in the expanded header.
I know what to do was waiting a lifetime for the form to come up. I blame the programmers - obviously it wasn't written in standard C++.
Yeah, I saw in other messages that you were using the usual quote
mechanism there. Google's a tough newsreader, I had to use it for about
four months in the early part of 2005. I feel your pain.
Brian
JustBoo wrote: You don't have to use Google.
http://www.forteinc.com/main/homepage.php
They have a free version that is very good.
This is getting O/T but from work google is the easiest (and possibly
only) option. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dan Perl |
last post by:
There is something with initializing mutable class attributes that I am
struggling with. I'll use an example to explain:
class Father:
attr1=None # this is OK
attr2= # this is wrong...
|
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.
...
|
by: Shea Martin |
last post by:
I have been programming in C++ for over 4 years. I *think* I knew that
a struct could have a constructor but I decided to dig into it a little
more today, and found that there is very little...
|
by: Chris |
last post by:
Hi,
I don't get the difference between a struct and a class !
ok, I know that a struct is a value type, the other a reference type, I
understand the technical differences between both, but...
|
by: ad |
last post by:
Is there any difference about namespace between VB.NET and C#.
All functions in c# must include in a namespace.
Why I can't find namespace in the files .vb .
How VB.NET implement the...
|
by: Shadow Lynx |
last post by:
If this is not the most appropriate group for this question, please let
me know.
I noticed an odd priority difference in resolving names in VS 2005 (VWD
Express) vs. the .NET 2.0 compiler (the...
|
by: Jess |
last post by:
Hello,
I understand the default-initialization happens if we don't initialize
an object explicitly. I think for an object of a class type, the
value is determined by the constructor, and for...
|
by: mthread |
last post by:
Hi,
I am learning C++ and I have been told that an object can be
created either by using calloc or new. If it is true, can some one
tell me what is the difference b/w using these two function...
|
by: Matt |
last post by:
Hi everyone,
can someone point out the difference between defining a class with the
public access modifier and just leaving it as it is (default in vs.net
"class")
I think that the default...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: 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: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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...
|
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...
|
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...
| |