473,698 Members | 2,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there anything in C++ akin to Java's class Object?

The reason why I ask is because I am unfamiliar with the idea of
templates. It seems like it would be easier if all classes that
needed something like

template<class T> class Stack { ... }

could be done with just some generic superclass, instead of using a
template.

If this is not the case, does the reason have something to do with
performance, or is it just an alternative that was not thought of?
Jul 22 '05 #1
21 1569
* Blue Ocean:
The reason why I ask is because I am unfamiliar with the idea of
templates. It seems like it would be easier if all classes that
needed something like

template<class T> class Stack { ... }

could be done with just some generic superclass, instead of using a
template.

If this is not the case, does the reason have something to do with
performance, or is it just an alternative that was not thought of?


Templates give static typechecking (at compile+link time).

A common base class gives dynamic typechecking (at run-time).

Static typechecking is superior for producing correct code, _and_
is generally also superior with respect to performance.

One downside is that templates in C++ are not well integrated with
the rest of the language, and are so complex that most compilers
don't support them fully, which in practice means that if you
intend to produce portable code it's not enough to follow the
Holy Standard; the code must tested with and adapted to the various
compilers of interest, and perhaps even be non-standard-conforming.

Another downside is that template code is generally very difficult to
debug and to maintain, so the idea is to code only very general and very
simple things as templates.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #2
On 7 Jul 2004 13:19:54 -0700, Blue Ocean <bl*********@ho tmail.com> wrote:
The reason why I ask is because I am unfamiliar with the idea of
templates. It seems like it would be easier if all classes that
needed something like

template<class T> class Stack { ... }

could be done with just some generic superclass, instead of using a
template.
With a generic super class you have to downcast when you retrieve the
object from the Stack. Doing that is either inefficent (if you use
dynamic_cast) or not type safe (if you use static_cast). Either way its
ugly. So I've always thought that this is a weakness of Java.

How many times have you written an application where you wanted to put
anything, literally objects of any type, onto a Stack. Almost always you
have one type or some small set of types in mind, this is what C++ lets
you do.

Why do you think Java's way is easier? I've always thought that they were
forced into generic super classes precisely because they didn't have
templates.

If this is not the case, does the reason have something to do with
performance, or is it just an alternative that was not thought of?


I'm sure it was thought of and rejected. Bjarne Stroupstrup was certainly
familar with Smalltalk, which has a generic superclass just like Java.
Jul 22 '05 #3
Something that calls itself Blue Ocean wrote:
The reason why I ask is because
I am unfamiliar with the idea of templates.
The obvious solution is to learn something about templates.
It seems like it would be easier if all classes that needed something like

template<class T> class Stack { ... }

could be done with just some generic superclass,
instead of using a template.
It *can* be done with "some generic superclass"
*besides* using templates!
If this is not the case,
does the reason have something to do with performance,
or is it just an alternative that was not thought of?


Class templates are preferred because
compile time optimizations can be applied to templates classes
that cannot be applied to classes with virtual functions.
Jul 22 '05 #4
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote in message news:<cc******* ***@nntp1.jpl.n asa.gov>...
[snip]


Troll alert? Don't you think that's a bit harsh? Pardon a newbie for
offending your sensibilities, but please don't jump to conclusions.
My experience is limited, so I came here for advice, not to be
lambasted by someone who can't deal with even a perceived (not real)
challenge to their opinions.

If my wording was a bit off, I'm sorry, but the way you responded was
totally uncalled for. I like C++ better than Java, and I'm not here
to put it down. If I was, I'd think of better ways of doing it than
pretending to be a newbie.
Jul 22 '05 #5
"John Harrison" <jo************ *@hotmail.com> wrote in message news:<opsasbi8d b212331@androni cus>...
On 7 Jul 2004 13:19:54 -0700, Blue Ocean <bl*********@ho tmail.com> wrote:

[snip]


Thanks for the help. I guess that what the other guy said about how
static type-checking is superior in general is true. Thinking about
it, I can't think of any case in which I would have put objects of two
different types into a collection last semester when I was using Java,
so static type checking would not have made a difference. And if the
performance is better, all the more reason to use it.
Jul 22 '05 #6
Blue Ocean wrote:
Troll alert? Don't you think that's a bit harsh?
Pardon a newbie for offending your sensibilities,
but please don't jump to conclusions.
My experience is limited, so I came here for advice,
not to be lambasted by someone
who can't deal with even a perceived (not real)
challenge to their opinions.
If my wording was a bit off, I'm sorry,
but the way you responded was totally uncalled for.
It certainly was called for.
I like C++ better than Java, and I'm not here to put it down.
If I was, I'd think of better ways of doing it
than pretending to be a newbie.


You use a troll handle (Blue Ocean) instead of your given name.
You post from a disposable email account (bl*********@ho tmail.com).
Your Java and C++ comparison appears intended to incite a language war.
There is *good* reason to suspect that you are trolling.
Jul 22 '05 #7
On 7 Jul 2004 19:39:13 -0700, ag***********@g mail.com (Blue Ocean)
wrote:
"John Harrison" <jo************ *@hotmail.com> wrote in message news:<opsasbi8d b212331@androni cus>...
On 7 Jul 2004 13:19:54 -0700, Blue Ocean <bl*********@ho tmail.com> wrote:

[snip]


Thanks for the help. I guess that what the other guy said about how
static type-checking is superior in general is true. Thinking about
it, I can't think of any case in which I would have put objects of two
different types into a collection last semester when I was using Java,
so static type checking would not have made a difference. And if the
performance is better, all the more reason to use it.


Java 1.5 (due soon) adds generics to Java, using an implementation
that allows typesafe containers, but doesn't give you a performance
improvement. Better than nothing I suppose.

Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #8
On 7 Jul 2004 19:30:31 -0700, ag***********@g mail.com (Blue Ocean)
wrote:
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote in message news:<cc******* ***@nntp1.jpl.n asa.gov>...
[snip]


Troll alert? Don't you think that's a bit harsh?


Don't worry, his nickname is "Trollsdale "; random "Troll Alert"
postings are his speciality.

Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #9
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote in message news:<cc******* ***@nntp1.jpl.n asa.gov>...
Blue Ocean wrote:

You use a troll handle (Blue Ocean) instead of your given name.
You post from a disposable email account (bl*********@ho tmail.com).
Your Java and C++ comparison appears intended to incite a language war.
There is *good* reason to suspect that you are trolling.


My given name is James F. Aguilar. I've been trying to get Google to
show it for some time but even if I look, I can't find the place to
change what it displays. Now that I'm using a gmail account, please
understand that this is by no means a disposable e-mail address, since
they are by invite only and come with a lot of nice features that
hotmail doesn't have.

I will attempt to avoid posting Java/C++ comparisons in the future,
unless I absolutely must in order to obtain understanding.
Jul 22 '05 #10

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

Similar topics

0
6809
by: Ravi Tallury | last post by:
Hi We are having issues with our application, certain portions of it stop responding while the rest of the application is fine. I am attaching the Java Core dump. If someone can let me know what the issue is. Thanks Ravi
73
8019
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities as a standard portable part of the core language, the LISP package, and the java.lang package, respectively. Both have big integers, although only LISP has rationals as far as I can tell. Because CL supports keyword arguments, it has a wider range...
2
6956
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
2
1375
by: Noah Roberts | last post by:
I have a class, that inherits from a class that inherits virtually from another class. I have a breakdown occuring and it is not wrt the virtually inherited class but one of the other MIed pure virtual classes. I get this in my call stack at the point of explosion: Flo.exe!DDocument::Dispatch(DFZone * ptr=0x0298d260) Line 94 + 0x32 bytes C++ Flo.exe!DDocument::Dispatch(DFZone * __A0=0x0298d260) + 0x2f
0
15408
by: r035198x | last post by:
Overriding therefore allows you to use the same method name to refer to differently implemented methods. Here is an example using the famous shapes example. class Shape { public Shape() { } public double getArea() { return 5.0; }
15
2789
by: Xah Lee | last post by:
On Java's Interface Xah Lee, 20050223 In Java the language, there's this a keyword “interface”. In a functional language, a function can be specified by its name and parameter specs. For example: f(3) f(3, )
2
2960
by: inetjack | last post by:
Hi, This is a little test application, generating and compiling code at runtime. The loadClassLoader() method of the Factory Object suppose to unload all class previously loaded. It does not work!!! Somebody knows why?
2
3759
by: yeshello54 | last post by:
so here is my problem...in a contact manager i am trying to complete i have ran into an error..we have lots of code because we have some from class which we can use...anyways i keep getting an error when i do the following. if you add a contact with up to 13 fields it will be stored in a data structure. i have a tabbed pane that will show six of the 13 fields for that contact. when you double click the contact i want it to pop up and show all 13...
0
9170
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
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8871
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7739
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 projectplanning, coding, testing, and deploymentwithout 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...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4371
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
3052
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
2336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
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.