LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   A C++ tutorial I wanted to point out to everyone. (https://www.linuxquestions.org/questions/programming-9/a-c-tutorial-i-wanted-to-point-out-to-everyone-818284/)

pr_deltoid 07-06-2010 10:49 AM

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/

ericzqma 07-06-2010 11:25 AM

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.

Mr. Majestic 07-06-2010 03:53 PM

Thanks for posting, this looks like quite a nice resource.

konsolebox 07-07-2010 12:02 AM

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?

dugan 07-07-2010 12:13 AM

Quote:

Originally Posted by konsolebox (Post 4025811)
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.

konsolebox 07-07-2010 12:31 AM

Quote:

Originally Posted by dugan (Post 4025826)
Neither is free.

Guess it's safer to just have the online version.

zirias 07-07-2010 01:22 AM

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

konsolebox 07-07-2010 08:17 AM

@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.

zirias 07-07-2010 08:45 AM

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.

konsolebox 07-07-2010 08:51 AM

Quote:

Originally Posted by zirias (Post 4026281)
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.

zirias 07-07-2010 09:12 AM

Quote:

Originally Posted by konsolebox (Post 4026290)
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.

dugan 07-07-2010 09:25 AM

Quote:

Originally Posted by zirias (Post 4025871)
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

konsolebox 07-08-2010 05:18 AM

Quote:

Originally Posted by zirias (Post 4026304)
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.

pr_deltoid 07-08-2010 02:03 PM

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.


All times are GMT -5. The time now is 05:43 AM.