473,398 Members | 2,403 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,398 software developers and data experts.

Final and Cieled and nothing in C++

Has the fact that both Java and C# are garbage collected, and C++ in not,
anything to do with the fact that there is no language item to prevent a
class from being inherired from? I once read that Java and C# implement this
feature for preformance, but the C++ creators said it was not worse the
effort. So because Java and C# are garbage collected, in their case is it
worse the effort? What is the connection?
Feb 5 '06 #1
14 1740
My4thPersonality wrote:
Has the fact that both Java and C# are garbage collected,
and C++ in not, anything to do with the fact that there
is no language item to prevent a class from being
inherired from? I once read that Java and C# implement
this feature for preformance, but the C++ creators said
it was not worse the effort. So because Java and C# are
garbage collected, in their case is it worse the effort?
What is the connection?


"Why doesn't C++ have garbage collection?"
http://www.research.att.com/~bs/bs_f...age-collection
Feb 5 '06 #2

"My4thPersonality" <so*******@out.there> skrev i meddelandet
news:u2*************@TK2MSFTNGP10.phx.gbl...
Has the fact that both Java and C# are garbage collected, and C++ in
not, anything to do with the fact that there is no language item to
prevent a class from being inherired from? I once read that Java and
C# implement this feature for preformance, but the C++ creators said
it was not worse the effort. So because Java and C# are garbage
collected, in their case is it worse the effort? What is the
connection?


It is not about garbage collection, it is about vitual functions. In
C++, a function isn't virtual, unless you specifically make it so.
That pretty much removes the need to specify 'final' to make the
functions non-virtual again - just don't make it virtual in the first
place!

Also, you can prevent a C++ class from being inherited from, but
making its constructor private. This isn't used very much though. The
usual way is to add a note in the documentation, "This class isn't
designed for inheritance".
Bo Persson
Feb 5 '06 #3
Bo Persson wrote:
"My4thPersonality" <so*******@out.there> skrev i meddelandet
news:u2*************@TK2MSFTNGP10.phx.gbl...
Has the fact that both Java and C# are garbage collected, and C++ in
not, anything to do with the fact that there is no language item to
prevent a class from being inherired from? I once read that Java and
C# implement this feature for preformance, but the C++ creators said
it was not worse the effort. So because Java and C# are garbage
collected, in their case is it worse the effort? What is the
connection?


It is not about garbage collection, it is about vitual functions. In
C++, a function isn't virtual, unless you specifically make it so.
That pretty much removes the need to specify 'final' to make the
functions non-virtual again - just don't make it virtual in the first
place!

Also, you can prevent a C++ class from being inherited from, but
making its constructor private. This isn't used very much though. The
usual way is to add a note in the documentation, "This class isn't
designed for inheritance".


That said, final/sealed would be useful in C++ as an optimization, since
they allow the compiler to easily determine the final overrider of a virtual
function in some useful cases without doing whole program analysis. I think
that many C++ programmers would welcome the ability to mark a class as "not
inheritable". It's a common enough situation, and the idioms used to
prevent it in C++ are hacks at best, not proper language features. Easy to
get along without, yes, but still nice to have.

-cd
Feb 5 '06 #4
> In C++, a function isn't virtual, unless you specifically make it so.

And in Java and C# a function is virtual by default?

Feb 6 '06 #5
<ma*********@hotmail.com> wrote:
And in Java and C# a function is virtual by default?


Yes
Feb 6 '06 #6
ma*********@hotmail.com wrote:
In C++, a function isn't virtual, unless you specifically make it so.


And in Java and C# a function is virtual by default?


In Java it is. In C# it isn't.

Jon

Feb 6 '06 #7
And in Java and C# a function is virtual by default?

Jon
In Java it is. In C# it isn't.


Mmm...

Do both languages, Java and C#, actually have functions that are not
members of a class? They have not have they?

Feb 7 '06 #8
marcwent...@hotmail.com wrote:
In Java it is. In C# it isn't.


Mmm...

Do both languages, Java and C#, actually have functions that are not
members of a class? They have not have they?


Assuming you mean "methods which are not members of a type" - no. (I'm
being picky - "function" isn't a C# term, but structs *can* have
methods. I suspect we're on the same wavelength, but it's worth
clarifying just for the sake of posterity :)

Personally I wish that classes were sealed by default in C#, but then I
view inheritance as something to be used sparingly. (It's wonderful
where it *is* useful.)

Jon

Feb 7 '06 #9
Alex Blekhman:
http://www.research.att.com/~bs/bs_f...age-collection


More relevant would be this then:

"Why doesn't C++ have a final keyword?"

http://public.research.att.com/~bs/bs_faq2.html

But then, why would the lack of performance gain be relevant in Java,
but not relevant in C++.

Feb 7 '06 #10
ma*********@hotmail.com wrote:
Alex Blekhman:
http://www.research.att.com/~bs/bs_f...age-collection
More relevant would be this then:

"Why doesn't C++ have a final keyword?"

http://public.research.att.com/~bs/bs_faq2.html


Agree.
But then, why would the lack of performance gain be
relevant in Java, but not relevant in C++.


Sorry, I couldn't understand what you wanted to say.
Feb 7 '06 #11
> Sorry, I couldn't understand what you wanted to say.

Euh, well, I understand, follow the explination of Bjarne Stroustrup
that final has too little use to implement because the performance gain
in C++ would be little. But then I ask myself, why would the
performance gain in Java would be substantional.

"In C++, virtual function calls are so fast that their real-world use
for a class designed with virtual functions does not to produce
measurable run-time overheads compared to alternative solutions using
ordinary function calls."

Hence somehow, virtual functions in Java are slow and finalized
function a lot faster? Or it just a mre or less coincidental choice the
developers of both language decided to do and not do. By the way, I am
more in C++ then in Java and or C#, but I am studying the latter two
languages to broaden my knowledge.

Feb 7 '06 #12
ma*********@hotmail.com wrote:
Sorry, I couldn't understand what you wanted to say.
Euh, well, I understand, follow the explination of Bjarne
Stroustrup that final has too little use to implement
because the performance gain in C++ would be little.


No, B.Stroustrup mentions two common arguments of `final'
proponents. One is possible performance gain (when callin
virtual functions), second is safety (to prevent unwanted
derivation).
Hence somehow, virtual functions in Java are slow and
finalized function a lot faster? Or it just a mre or less
coincidental choice the developers of both language
decided to do and not do.


I don't think that `final' concept exists in Java solely
because of performance considerations. Moreover, I reckon
that performance has very little part in `final' argument.
It exists to provide class hierarchy designers with means to
ensure logic correctness. By applying `final' specifier
function doesn't cease to be "virtual" (as we understand it
in C++). It merely prevents farther derivations/overloading.
"Virtuality" still works until it finds final derivative.
Feb 7 '06 #13

<ma*********@hotmail.com> skrev i meddelandet
news:11**********************@g14g2000cwa.googlegr oups.com...
Sorry, I couldn't understand what you wanted to say.
Euh, well, I understand, follow the explination of Bjarne Stroustrup
that final has too little use to implement because the performance
gain
in C++ would be little. But then I ask myself, why would the
performance gain in Java would be substantional.


Because in C++ functions are not virtual by default, so the use for
final is limited.

"In C++, virtual function calls are so fast that their real-world
use
for a class designed with virtual functions does not to produce
measurable run-time overheads compared to alternative solutions
using
ordinary function calls."
On C++, a function is virtual only if explicitly made so. That
probably is part of the interface design for subclasses, so there is s
genuine need for the function to be virtual.

Again, the few exceptions from this doesn't make it worthwhile to
introduce a new concept. A small gain in very few places. Is it worth
it?

Hence somehow, virtual functions in Java are slow and finalized
function a lot faster? Or it just a mre or less coincidental choice
the
developers of both language decided to do and not do. By the way, I
am
more in C++ then in Java and or C#, but I am studying the latter two
languages to broaden my knowledge.


There are a lot more vitual functions in Java, so there are more
opportunities for finalizing functions. I also suspect that early Java
systems didn't optimize as well as C++ compilers can do. Perhaps the
gain used to be greater?
Bo Persson
Feb 7 '06 #14
Alex:
Because in C++ functions are not virtual by default, so the use for
final is limited.


Ok, so in C++ I just do not declare a function as virtual, while in
Java I explicitly declare it final because it is java-virtual by
default. Hence considering functionality I already got an alternative
in C++.

I thank you and Bo, and the others for the explination. It's clearer
now.

Feb 8 '06 #15

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

Similar topics

1
by: Anthony Martin | last post by:
I've been reading the Java Language Specification, and in Chapter 16 there's an interesting topic called Definite Assignment. http://tinyurl.com/3fqk8 I'm wondering about the idea of "Deferred...
0
by: Anthony Baxter | last post by:
To go along with the 2.4a3 release, here's an updated version of the decorator PEP. It describes the state of decorators as they are in 2.4a3. PEP: 318 Title: Decorators for Functions and...
0
by: Gary Broughton | last post by:
Thanks to everybody for all your help and advice. It seems Linux is going to HAVE to be the next step, but while I know sod all about it, I have enlisted the help of a colleague to assist with...
10
by: Bezalel Bareli | last post by:
I know I have seen some threads on the subject long time ago and it was using a virtual base class ... in short, what is the nicest way to implement the Java final class in c++ Thanks.
0
by: Geir Baardsen | last post by:
Hi! I was a little too fast, because I had a new crash in what I thought was a solution. Then I discovered Allen Browne's webpage: members.iinet.au/~allenbrowne, and found a procedure I thought I...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
5
by: Anthony Baxter | last post by:
On behalf of the Python development team and the Python community, I'm happy to announce the release of Python 2.4.3 (final). Python 2.4.3 is a bug-fix release. See the release notes at the...
14
by: Rahul | last post by:
Hi Everyone, I was searching for final class in c++, and i came across few links which suggests to have the constructor of the, to be final class, as private so that any derived class's...
5
by: kiran | last post by:
Hi all, How can we stop a base class to be derived in C++? In java we do that using final keyword. Is there a c++ equivalent? Thanks in advance, Kiran
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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,...
0
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,...
0
jinu1996
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...
0
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...
0
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...

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.