By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,385 Members | 1,739 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,385 IT Pros & Developers. It's quick & easy.

Default call of an Empty class object

P: n/a
what will a object of an Empty class( contain nothing), do on
default.What are all the default methods it calls. what is the use of
creating the object for an empty class?

Dec 26 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
On 25 Dec 2005 22:15:51 -0800, "meendar"
<as****************@gmail.com> wrote:
what will a object of an Empty class( contain nothing), do on
default.What are all the default methods it calls. what is the use of
creating the object for an empty class?


C++ has no "methods", only functions and member functions.

What do you mean by empty? No data members? No member functions?

An object by itself does not call any functions. Your program calls
the functions. The constructor (or one constructor out of several if
there are more than one) is called when the object is created, and the
destructor is called when it is destroyed. But your program is
responsible for creation and deletion, so here it is also your program
that calls these, at least indirectly.

Consider the following:

struct Empty {};

I suppose that is as close as one can come to an empty class. However,
the C++ standard requires stand-alone objects of such empty classes to
have non-zero size (see section 9.2). If Empty is used as a base
class, the compiler is allowed to optimize its size away to zero bytes
within the derived class. Since we declared no default constructor,
destructor or assignment operator, the compiler generates these for
us. You can create objects of this class. Such empty classes are often
used in exception handling where the type is the only thing of
interest.

--
Bob Hairgrove
No**********@Home.com
Dec 26 '05 #2

P: n/a
Bob Hairgrove wrote:
On 25 Dec 2005 22:15:51 -0800, "meendar"
<as****************@gmail.com> wrote:

what will a object of an Empty class( contain nothing), do on
default.What are all the default methods it calls. what is the use
of creating the object for an empty class?

C++ has no "methods", only functions and member functions.


Isn't it a naming convention?
Word "method" is used also in the "The C++ Programming Language", 3rd
Ed. by Bjarne Stroustrup, chapter 10.2.1 (I have only polish
translation, so I'm not able to quote the original):

"member function (method)"

Cheers
--
Mateusz Łoskot
http://mateusz.loskot.net
Dec 26 '05 #3

P: n/a
On Mon, 26 Dec 2005 17:44:46 +0100, Mateusz ?oskot
<se****@signature.net> wrote:
Bob Hairgrove wrote:
C++ has no "methods", only functions and member functions.
Isn't it a naming convention?


No.
Word "method" is used also in the "The C++ Programming Language", 3rd
Ed. by Bjarne Stroustrup, chapter 10.2.1 (I have only polish
translation, so I'm not able to quote the original):

"member function (method)"

Cheers


I have the original ... it says "Member functions".

--
Bob Hairgrove
No**********@Home.com
Dec 26 '05 #4

P: n/a
Bob Hairgrove wrote:
On Mon, 26 Dec 2005 17:44:46 +0100, Mateusz ?oskot
Word "method" is used also in the "The C++ Programming Language", 3rd
Ed. by Bjarne Stroustrup, chapter 10.2.1 (I have only polish
translation, so I'm not able to quote the original):

"member function (method)"


I have the original ... it says "Member functions".


Hm, in my copy (translation of 3rd edition) I have explicitly

"member function (method)"

I have word "method" in parenthesis.
Cheers
--
Mateusz Łoskot
http://mateusz.loskot.net
Dec 26 '05 #5

P: n/a
Mateusz Loskot wrote:
Bob Hairgrove wrote:
On Mon, 26 Dec 2005 17:44:46 +0100, Mateusz ?oskot
Word "method" is used also in the "The C++ Programming Language",
3rd Ed. by Bjarne Stroustrup, chapter 10.2.1 (I have only polish
translation, so I'm not able to quote the original):

"member function (method)"


I have the original ... it says "Member functions".


Hm, in my copy (translation of 3rd edition) I have explicitly

"member function (method)"

I have word "method" in parenthesis.


How can a Polish translation have English words in it? And don't
mean the source code.
Dec 27 '05 #6

P: n/a
Victor Bazarov wrote:
Hm, in my copy (translation of 3rd edition) I have explicitly

"member function (method)"

I have word "method" in parenthesis.


How can a Polish translation have English words in it? And don't
mean the source code.


I said I'm not quoting, I'm translating back to english.
There is possibility that polish translator has changed the meaning of
those statements, so my re-translation is not accurate.

Victor, do you know polish?

Here are a few examples from Bjarne's book:
(without polish accents)

Title of the chapter:

10.2.1 Funkcje skladowe

It does mean "Member functions"

and inside the chapter is:

"Funkcje zadeklarowane wewnatrz definicji klasy nazywane funkcjami
skladowymi (metodami)..."

what does mean:

"Functions declared inside class definition are called member functions
(methods)..."

Another chapter title:

10.2.6 Metody stale

what means: "Const methods"

As I said, may be this translation is not accurate.
And - what I understand from Bob's posts - this translation
may be even incorrect.

Cheers
--
Mateusz oskot
http://mateusz.loskot.net
Dec 27 '05 #7

P: n/a
Mateusz Loskot wrote:
Victor Bazarov wrote:
Hm, in my copy (translation of 3rd edition) I have explicitly

"member function (method)"

I have word "method" in parenthesis.
How can a Polish translation have English words in it? And don't
mean the source code.


I said I'm not quoting, I'm translating back to english.
There is possibility that polish translator has changed the meaning of
those statements, so my re-translation is not accurate.

Here are a few examples from Bjarne's book:
(without polish accents)

Title of the chapter:

10.2.1 Funkcje skladowe

It does mean "Member functions"

and inside the chapter is:

"Funkcje zadeklarowane wewnatrz definicji klasy nazywane funkcjami
skladowymi (metodami)..."

what does mean:

"Functions declared inside class definition are called member functions
(methods)..."


This was added in the translation. The original reads

"Functions declared within a class definition [..] are called member
functions and can be invoked [...]"
Another chapter title:

10.2.6 Metody stale

what means: "Const methods"
The original reads "Constant Member Functions".
As I said, may be this translation is not accurate.
And - what I understand from Bob's posts - this translation
may be even incorrect.


It is.
Jonathan

Dec 27 '05 #8

P: n/a
Jonathan Mcdougall wrote:
Mateusz Loskot wrote:
As I said, may be this translation is not accurate.
And - what I understand from Bob's posts - this translation
may be even incorrect.

It is.


Thanks, now it's clear.
It's also a good argument for buying original books not translations.
Cheers
--
Mateusz Łoskot
http://mateusz.loskot.net
Dec 27 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.