LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-06-2010, 10:49 AM   #1
pr_deltoid
Member
 
Registered: Jun 2010
Distribution: Fedora
Posts: 289

Rep: Reputation: 41
Exclamation A C++ tutorial I wanted to point out to everyone.


I came across this free C++ book (C++ and QT) that is apparently very good. I'm reading it right now. If you want to learn about C++ and QT at the same time (and going by the looks of it and the table of contents, a lot about both), this book is great:
http://cartan.cas.suffolk.edu/oopdocbook/opensource/
 
Old 07-06-2010, 11:25 AM   #2
ericzqma
LQ Newbie
 
Registered: Jan 2010
Location: Hong Kong
Distribution: Fedora
Posts: 15
Blog Entries: 1

Rep: Reputation: 1
It introduces QT and C++, but it focuses on design pattern in my opinion.

It's a nice resource Thanks! I have bookmarked it for reference.
 
Old 07-06-2010, 03:53 PM   #3
Mr. Majestic
Member
 
Registered: Dec 2009
Location: Ohio
Distribution: Ubuntu, slackware, fedora, gentoo
Posts: 53

Rep: Reputation: 17
Thanks for posting, this looks like quite a nice resource.
 
Old 07-07-2010, 12:02 AM   #4
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Thanks, I find it useful. Is there a way a have an offline copy of the doc (that doesn't directly fetch the pages; packaged)? ;.. permissions?
 
Old 07-07-2010, 12:13 AM   #5
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: Slackware
Posts: 8,161

Rep: Reputation: 3294Reputation: 3294Reputation: 3294Reputation: 3294Reputation: 3294Reputation: 3294Reputation: 3294Reputation: 3294Reputation: 3294Reputation: 3294Reputation: 3294
Quote:
Originally Posted by konsolebox View Post
Is there a way a have an offline copy of the doc (that doesn't directly fetch the pages; packaged)?
Yes. It's also available as a bound book and an ebook. Neither is free.

http://www.informit.com/store/produc...sbn=0131879057

The bound version is available at most bookstores.

Last edited by dugan; 07-07-2010 at 12:16 AM.
 
Old 07-07-2010, 12:31 AM   #6
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by dugan View Post
Neither is free.
Guess it's safer to just have the online version.
 
Old 07-07-2010, 01:22 AM   #7
zirias
Member
 
Registered: Jun 2010
Posts: 361

Rep: Reputation: 59
As far as I can see, it misses two important aspects of C++ that are different from many other OOP languages and that you really should know about in order to write GOOD C++ code.

First, the paradigm "Resource Acquisition Is Initialization". It's important to do as much as possible in the member initialization list of a C++ constructor. You can read more about it here:
http://www.devx.com/getHelpOn/10Minu...ion/17298/1954
http://en.wikipedia.org/wiki/Resourc...Initialization

The other important issue is to properly understand why and when exactly destructors need to be declared "virtual":
http://blogs.msdn.com/b/oldnewthing/...07/127826.aspx
 
Old 07-07-2010, 08:17 AM   #8
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
@zirias Well for me it's ok. I don't really follow standards or common philosophies on how C++ should be coded. I always use C++ to its fullest capability. I actually decide on how features of C++ should be used with a balance between speed or efficiency, and readability or design.
 
Old 07-07-2010, 08:45 AM   #9
zirias
Member
 
Registered: Jun 2010
Posts: 361

Rep: Reputation: 59
konsolebox:

1.) if you DON'T understand the initialization concept of C++, you WILL run in unnecessary problems, for example with the creation of objects on the stack or with static initialization, and you start to code "workarounds" that aren't really needed and are inefficient.

2.) if you fail to provide a virtual destructor where it's needed, you risk memory leaks and similar bugs. if you provide one where it is not needed, you introduce inefficiency through an unneeded vtable.

So, I think it is very important to mention these things in any work trying to teach C++, at least in a later "advanced" chapter.
 
Old 07-07-2010, 08:51 AM   #10
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by zirias View Post
konsolebox:

1.) if you DON'T understand the initialization concept of C++, you WILL run in unnecessary problems, for example with the creation of objects on the stack or with static initialization, and you start to code "workarounds" that aren't really needed and are inefficient.
I also debug C++ code. That really depends on the compiler and not really on the concept. No?

Quote:
2.) if you fail to provide a virtual destructor where it's needed, you risk memory leaks and similar bugs. if you provide one where it is not needed, you introduce inefficiency through an unneeded vtable.
Again that depends on the compiler.
Quote:
So, I think it is very important to mention these things in any work trying to teach C++, at least in a later "advanced" chapter.
I agree but I only need at least the ideal link for C++ and Qt4. The tutorial is quite enough for me. Optimizations will be done later. objdump can wait

Edit: I'm not implying that I don't use virtuals. In fact I even use them often. The only thing is that whatever it is that discussed in the tutorial, common philosophies of C++ for me won't matter to it.

And I think I have enough common sense for the things I need to use and the risks if I don't use them so I don't think I really have to follow standards.

Last edited by konsolebox; 07-07-2010 at 08:59 AM.
 
Old 07-07-2010, 09:12 AM   #11
zirias
Member
 
Registered: Jun 2010
Posts: 361

Rep: Reputation: 59
Quote:
Originally Posted by konsolebox View Post
I also debug C++ code. That really depends on the compiler and not really on the concept. No?
There are a lot of issues related to member initialization where the compiler implementation has no choice when following the language standard. A typical example is a non-static member that has to be declared const for some reason. The only way to properly initialize ist, is in the member initialization list.

Of course, you don't really HAVE to understand the concept of coupling resource allocation to initialization that lead to this syntactical construct; it's probably enough to know that it's best to use it as much as possible -- but still you should (somehow) know about it in order to be a good C++ programmer.

Quote:
Again that depends on the compiler.
Maybe a compiler could chose to create a vtable even without virtual member functions -- that would be kind of a stupid implementation. The other way around, a good compiler could warn you about not using a virtual destructor where it is probably needed, but that would still be a guess

Quote:
And I think I have enough common sense for the things I need to use and the risks if I don't use them so I don't think I really have to follow standards.
Uhm, even if you chose to write some ISO-C89-style code and compile it with a C++ compiler, you still follow the standard

And if you're so sure you won't fall for these not-so-uncommon problems, it's ok, I still think a thread where a specific tutorial is recommended to anyone wanting to learn the language is a quite good place to give additional tips missing from the tutorial. I didn't say anything about all the topics actually covered in the tut, they're probably quite good.
 
Old 07-07-2010, 09:25 AM   #12
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: Slackware
Posts: 8,161

Rep: Reputation: 3294Reputation: 3294Reputation: 3294Reputation: 3294Reputation: 3294Reputation: 3294Reputation: 3294Reputation: 3294Reputation: 3294Reputation: 3294Reputation: 3294
Quote:
Originally Posted by zirias View Post
The other important issue is to properly understand why and when exactly destructors need to be declared "virtual":
This official answer was on Bjarnes Stroustrup's homepage forever.

http://www2.research.att.com/~bs/bs_...l#virtual-dtor

Last edited by dugan; 07-08-2010 at 08:45 AM.
 
Old 07-08-2010, 05:18 AM   #13
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by zirias View Post
There are a lot of issues related to member initialization where the compiler implementation has no choice when following the language standard. A typical example is a non-static member that has to be declared const for some reason. The only way to properly initialize ist, is in the member initialization list.

Of course, you don't really HAVE to understand the concept of coupling resource allocation to initialization that lead to this syntactical construct; it's probably enough to know that it's best to use it as much as possible -- but still you should (somehow) know about it in order to be a good C++ programmer.


Maybe a compiler could chose to create a vtable even without virtual member functions -- that would be kind of a stupid implementation. The other way around, a good compiler could warn you about not using a virtual destructor where it is probably needed, but that would still be a guess



Uhm, even if you chose to write some ISO-C89-style code and compile it with a C++ compiler, you still follow the standard

And if you're so sure you won't fall for these not-so-uncommon problems, it's ok, I still think a thread where a specific tutorial is recommended to anyone wanting to learn the language is a quite good place to give additional tips missing from the tutorial. I didn't say anything about all the topics actually covered in the tut, they're probably quite good.
Ok. I guess you're mostly right. That I'll mostly agree.
 
Old 07-08-2010, 02:03 PM   #14
pr_deltoid
Member
 
Registered: Jun 2010
Distribution: Fedora
Posts: 289

Original Poster
Rep: Reputation: 41
I've postponed reading that tutorial, actually.
I've decided to start with the official Qt book, found here: http://www.qtrac.eu/C++-GUI-Programm...t-4-1st-ed.zip
The other tutorial is good, but this is more of what I've personally been looking for.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP-MySQL tutorial and Linux Networking tutorial needed Please dlux45 Linux - Software 6 04-19-2010 01:10 PM
LXer: Tutorial: Point-and-Click Linux LVM Filesystem Workstation Backup, Part 2 LXer Syndicated Linux News 0 05-31-2007 04:01 PM
LXer: Tutorial: Point-and-Click Linux LVM Filesystem Workstation Backup, Part 1 LXer Syndicated Linux News 0 05-24-2007 10:47 PM
Can someone just point me to a tutorial... cautious Ubuntu 30 08-12-2006 07:16 AM
linux device driver tutorial wanted vijaykumar_gn Linux - Software 1 09-06-2003 10:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration