C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Knowing Java, learning C++, heavily confused

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Flow Nnamllub
Guest





PostPosted: Sat Aug 28, 2004 2:47 am    Post subject: Knowing Java, learning C++, heavily confused Reply with quote



Hi there,
this is my first post to the list, hope i am not breaking any written or
unwritten laws.

I am learning C++ by reading an introductory book right now. Does C++
have class libraries like java does? and is there any kind of documentation
like the java html docs where you can find all the stuff you need for
programming? right now i am not even capable of writing a simple filereader
io class, is there a place on the web where I could find a few C++ code
examples readable to a noob? Any suggestions highly welcomed!

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Sean Kelly
Guest





PostPosted: Sat Aug 28, 2004 10:56 am    Post subject: Re: Knowing Java, learning C++, heavily confused Reply with quote



Flow Nnamllub wrote:
Quote:

I am learning C++ by reading an introductory book right now. Does C++
have class libraries like java does? and is there any kind of documentation
like the java html docs where you can find all the stuff you need for
programming? right now i am not even capable of writing a simple filereader
io class, is there a place on the web where I could find a few C++ code
examples readable to a noob? Any suggestions highly welcomed!

One of the best online references is here: http://www.sgi.com/tech/stl/
If you're willing to go to the bookstore however, "Accelerated C++:
Practical Programming by Example" by A. Koenig and B. Moo is an
excellent introduction to the language. If that turns out to be a bit
too basic you might want to look at "The C++ Programming Language" by B.
Stroustrup.


Sean

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Terje Slettebø
Guest





PostPosted: Sat Aug 28, 2004 11:06 am    Post subject: Re: Knowing Java, learning C++, heavily confused Reply with quote



"Flow Nnamllub" <wbullma (AT) ibr (DOT) cs.tu-bs.de> wrote

Quote:
Hi there,
this is my first post to the list, hope i am not breaking any written or
unwritten laws.

Not at all. Welcome. :)

Quote:
I am learning C++ by reading an introductory book right now. Does C++
have class libraries like java does?

It does have a standard library, some of it being classes, yes.

Quote:
and is there any kind of documentation
like the java html docs where you can find all the stuff you need for
programming?

There isn't really a central place for such things for C++, that I know of.
There are a few sites with tutorials, references, etc. Googling for it, I
found these:

http://www.cplusplus.com/ (which contains a tutorial, and a partial library
reference)
http://www.cppreference.com/ (another reference site)
http://www.dinkumware.com/manuals/reader.aspx?lib=cpp (another one)

As you say you're reading, I recommend a good book on the language. The
language is quite a bit more complex than Java, but using the standard
library, it should be possible to do a relatively smooth transition. I
recommend the book "Accelerated C++", which takes this approach - starting
with C++ as a high-level language (rather than starting from C).

I can also recommend the accu-general mailing list, found here
([url]http://www.accu.org)[/url], which is open for all, and has a friendly
athmosphere.

Quote:
right now i am not even capable of writing a simple filereader
io class, is there a place on the web where I could find a few C++ code
examples readable to a noob? Any suggestions highly welcomed!

For this particular example, theres a stream tutorial here:
http://www.cplusplus.com/doc/tutorial/tut6-1.html

I went the other way: learning Java after C++, so I can sympathise with your
situation. I hope you'll find C++ to be an enjoyable experience. :)

One of the biggest gotchas I found, going from C++ to Java, is how the same
or similar things can mean different things in the two languages. Take for
example a linked list node in Java:

class Node
{
Node previous;
Node next;
}

If we write the same in C++, it means something different (and it won't even
compile):

class Node
{
Node previous;
Node next;
};

In Java, as you know, objects are always passed by reference. In contrast,
the same syntax in C++ means passing by _value_. So instance variable
declarations like the above, in Java, it declares two references to Node
objects, while in the C++ example, it declares two _objects_ of type Node.
As these are nested in the Node class, itself, it would mean a recursive
nesting, and we get an error.

The Java version is roughly equivalent to the following C++ version:

class Node
{
Node *previous;
Node *next;
};

Note the "*"'s, declaring the instance variables as pointers, which is
roughly the same as Java's references. C++ also have references, but they
can't be rebound after they are bound to an object (and can't be null), so
they work differently.

Regards,

Terje



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Bronek Kozicki
Guest





PostPosted: Sun Aug 29, 2004 11:09 am    Post subject: Re: Knowing Java, learning C++, heavily confused Reply with quote

Sean Kelly wrote:
Quote:
One of the best online references is here: http://www.sgi.com/tech/stl/

I discourage everyone from using this as a reference. It's documentation
of the Standard Template Library, which is *not* the same as C++
standard library (but often confused). STL is obsolete and no modern C++
compiler should be expected to fully support it . Online reference of
Dinkumware implementation of the C++ standard library (good one,
arguably among the best) is available at
http://www.dinkumware.com/refxcpp.html . Great handbook of the C++
standard library is Josuttis http://www.josuttis.com/libbook/index.html

Quote:
If you're willing to go to the bookstore however, "Accelerated C++:
Practical Programming by Example" by A. Koenig and B. Moo is an
excellent introduction to the language. If that turns out to be a bit
too basic you might want to look at "The C++ Programming Language" by B.
Stroustrup.

Right


B.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Rui Maciel
Guest





PostPosted: Sun Aug 29, 2004 11:16 am    Post subject: Re: Knowing Java, learning C++, heavily confused Reply with quote

Flow Nnamllub wrote:
Quote:
Hi there,
this is my first post to the list, hope i am not breaking any written or
unwritten laws.

I am learning C++ by reading an introductory book right now. Does C++
have class libraries like java does?

C++ has indeed a standard library. Unfortunatelly for you (and everyone
who comes from the java world), the C++ standard library doesn't
resemble the java class libraries, which include everything plus the
kichen sink. If you wish to do some GUI building, database work or
networking, you must choose what library you want to use and install it.

Quote:
and is there any kind of documentation
like the java html docs where you can find all the stuff you need for
programming?

If you wish to get your hands on C++ references, google is your friend.

Quote:
right now i am not even capable of writing a simple filereader
io class, is there a place on the web where I could find a few C++ code
examples readable to a noob? Any suggestions highly welcomed!

try sourceforge. They have tons of open source C++ projects in there.
Some of them may interest you.


<snip>

And by the way, stay away from Visual C++, specially the earlier versions.


Hope this helps
Rui Maciel

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
M Jared Finder
Guest





PostPosted: Sun Aug 29, 2004 10:42 pm    Post subject: Re: Knowing Java, learning C++, heavily confused Reply with quote

Rui Maciel wrote:

Quote:
snip

And by the way, stay away from Visual C++, specially the earlier versions.

I disagree. The latest version of Visual C++ (version 7.1, marketing
version 2003) has extremely good standard support. Just make sure to
set the all the standard conformance compilation flags to on.

-- MJF

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Steven T. Hatton
Guest





PostPosted: Mon Aug 30, 2004 10:41 am    Post subject: Re: Knowing Java, learning C++, heavily confused Reply with quote

Bronek Kozicki wrote:

Quote:
Sean Kelly wrote:
Online reference of
Dinkumware implementation of the C++ standard library (good one,
arguably among the best) is available at
http://www.dinkumware.com/refxcpp.html . Great handbook of the C++
standard library is Josuttis http://www.josuttis.com/libbook/index.html

I finally realized what I find awkward when using this very good book as a
reference. It lacks the kind of edge tabs you find in the 'nutshell'
books. This really is a good book. I wouldn't discourage anyone for
buying it.

I've found the C++ Pocket Reference described here:

http://www.oreilly.com/catalog/cpluspluspr/index.html

to be worth having around. It is not the thing to read as an introduction
to C++, but it is a useful, concise reference for the core language. There
is a companion book for the Standard Library, but I have no experience with
that volume.

I've also found the actual ISO/IEC 14882:2003 to be useful as a reference to
the Library. It is certainly _not_ something for a beginner to depend on
exclusively.

Another very nice resource for the core language is

http://publib.boulder.ibm.com/infocenter/comphelp/index.jsp
?topic=/com.ibm.vacpp6a.doc/language/ref/exceptions.cplr162.htm

I just noticed they now have a standard library reference as well. The
documentation is written for AIX, but they did a very good job of
indicating what parts are IBM extensions.

Quote:
If you're willing to go to the bookstore however, "Accelerated C++:
Practical Programming by Example" by A. Koenig and B. Moo is an
excellent introduction to the language. If that turns out to be a bit
too basic you might want to look at "The C++ Programming Language" by
B. Stroustrup.
After a few false starts with C++, I forced myself to read Stroustrup's

TC++PL(SE). I too was coming from a mostly Java background. It took me a
while to understand the fundamental differences. C++ skills were far more
difficult for me to acquire than Java had been. I suspect Accelerated C++
is a better beginner book than Stroustrup's. Getting through that book was
one of the most challenging exercises I've ever undertaken. And I am very
certain there is much I could learn by reading it again.

Here are some of the points that I believe a person coming from Java should
focus on:

Establish good practices regarding the use of header files and 'source'
files. Header files are a necessary evil of working with C++

Get used to calling a "super class" a "base class", a "subclass" a "derived
class", and "subclassing" "deriving". "Methods" are generally called
"member functions", and the word method is often reserved for "pure virtual
member functions". "pure virtual member functions" are what Java calls
"abstract methods". Classes that have "pure virtual member functions" are
called "abstract", and are like "abstract classes" in Java, in that they
cannot be instantiated.

Know what a reference is. They are tricky if you don't clearly understand
what they are, and the consequences of assigning to them, passing them as
arguments or return values, etc.

Understand pointers. They are a bit easier to comprehend than references,
but they also can be tricky.

Know what const does in the different places it can be used.

Start looking at templates, but don't try to master them before you have a
reasonable grasp of the more fundamental aspects of the language. Keep
revisitting them form time to time so that your eyes will become accustomed
to the notation.

Know what a /virtual function table/ is, and why classes without virtual
functions don't have them. Understand how this impacts polymorphism.

Understand why you need to use pointers or references to utilize the
polymorphic behavior of an object.

Know what a dynamic_cast is, and how to use it to distinguish between
different types when objects of derived types are pointed to by a pointer
to a base class of the actual object's type. Know how this works with
references, and what the difference between dynamic_cast on a pinter verse
dynamic_cast on a reference is.

Understand that assignment is different than initialization, and how and why
they differ.

Initialize all your pointers, as well as all your built-in type member
variables. C++ won't do that for you.

Don't expect to get up to speed as quickley with C++ as you did with Java.
At least that's how it worked for me. I still have much to learn. C++ does
not support things like synchronization and threading, "out-of-the-box".
That requires additional libraries beyond what the Standard provides.
--
Regards,
Steven

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Mike Capp
Guest





PostPosted: Mon Aug 30, 2004 10:46 am    Post subject: Re: Knowing Java, learning C++, heavily confused Reply with quote

Rui Maciel <rui_maciel (AT) mail (DOT) com> wrote
Quote:
Flow Nnamllub wrote:
this is my first post to the list, hope i am not breaking any written or
unwritten laws.

("You" here refers to Wolf rather than Rui)

Not at all. Actually, Francis Glassborow (one of the moderators here)
is currently writing a book on learning C++ as a second language and
would probably be delighted to hear from you.

Quote:
try sourceforge. They have tons of open source C++ projects in there.
Some of them may interest you.

Some of them are downright scary, though, so be careful what you pick
to learn from. I vividly recall fleeing screaming from one project
when I found a (3d transform) Matrix class inheriting publicly from
IdentityMatrix. You might try the gtkmm source - it's big enough to be
meaty, and seemed to have a good, modern, idiomatic design from my
brief peek.

Quote:
And by the way, stay away from Visual C++, specially the earlier versions.

A little harsh. VC7/7.1 was pretty good regarding Standard compliance,
and the VC8 "Express" beta is both free and decent. Just remember to
disable language extensions (/Za). He's right about the earlier
versions though.

cheers,
Mike

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Bronek Kozicki
Guest





PostPosted: Tue Aug 31, 2004 10:06 am    Post subject: Re: Knowing Java, learning C++, heavily confused Reply with quote

Steven T. Hatton wrote:
Quote:
I suspect Accelerated C++
is a better beginner book than Stroustrup's.


Definitely it is. I strongly suggest it to anyone starting with C++,
*especially* to those with experience with other programming languages -
it really helps to understand why C++ is different, and does not dilute
with other programming languages (notably C)

As to your other points: when learning difference dynamic_cast and
static_cast , one has to know and understand difference between static
type and dynamic type. Static type safety is fundamental concept in C++
, and might be strage to someone used to Java. The other thing is : do
not reinvent the wheel and use standard C++ library when appropriate
instead of creating own collections, algorithms, playing with
(insecure!) null-terminated-C-style-strings etc.


B.






[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
kanze@gabi-soft.fr
Guest





PostPosted: Tue Aug 31, 2004 7:25 pm    Post subject: Re: Knowing Java, learning C++, heavily confused Reply with quote

[email]mike.capp (AT) gmail (DOT) com[/email] (Mike Capp) wrote in message
news:<ffc27447.0408291416.855b55e (AT) posting (DOT) google.com>...
Quote:
Rui Maciel <rui_maciel (AT) mail (DOT) com> wrote
Flow Nnamllub wrote:
this is my first post to the list, hope i am not breaking any
written or unwritten laws.

("You" here refers to Wolf rather than Rui)

Not at all. Actually, Francis Glassborow (one of the moderators here)
is currently writing a book on learning C++ as a second language and
would probably be delighted to hear from you.

try sourceforge. They have tons of open source C++ projects in there.
Some of them may interest you.

Some of them are downright scary, though, so be careful what you pick
to learn from. I vividly recall fleeing screaming from one project
when I found a (3d transform) Matrix class inheriting publicly from
IdentityMatrix. You might try the gtkmm source - it's big enough to be
meaty, and seemed to have a good, modern, idiomatic design from my
brief peek.

I'm curious about this. If learning is the goal, I'd say that you do
want to learn idiomatic *modern* C++. If portability is the goal (as is
often the case in freeware projects), you generally can't use idiomatic,
modern C++, because you'll have to support compilers that don't support
it. (Try compiling Boost with Sun CC if you want an example of what I
mean. More generally, VC++ 6.0 and g++ 2.95.[23] seem to be among the
most widely used compilers today, even though neither is particularly
modern; I suspect that most freeware projects would want to support both
of them, which means strstream instead of stringstream, no locale, no
numeric_limits and only very simple templates.)

Quote:
And by the way, stay away from Visual C++, specially the earlier
versions.

A little harsh. VC7/7.1 was pretty good regarding Standard compliance,
and the VC8 "Express" beta is both free and decent. Just remember to
disable language extensions (/Za). He's right about the earlier
versions though.

That's true for the earlier versions of most compilers, however. In its
time, VC++ 6.0 was considerably in advance of its contemporaries, such
as g++ 2.95.2 or Sun CC 5.1.

--
James Kanze GABI Software http://www.gabi-soft.fr
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.