C++ Primer (5th Edition)

Author: Stanley B. Lippman, Josée Lajoie, Barbara E. Moo
All Stack Overflow 8
This Year Stack Overflow 2
This Month Stack Overflow 1


by anonymous   2018-07-19
Go read [C++ Primer](https://www.amazon.com/dp/0321714113). Here: https://pastebin.com/raw/cfSknXJ7
by gusmd   2018-04-04
If you are willing to read a book, I strongly recommend the C++ Primer, 5th ed., by Lipmann et al. [0]

It's a very didactic book, covering C++11 well. Unfortunately it does not cover C++14 or C++17, but if you are just starting out with C++ I don't think that's an issue -- most shops are still on 11 or older, anyways...

[0] https://www.amazon.com/dp/0321714113

by tolger   2018-03-10
I found "C++ Primer" by Lippman et al very well written and comprehensive. It includes C++11 features and every chapter has exercises to make sure you understand the content.


by anonymous   2018-01-29
Not all professors do, unfortunately. Last week I interviewed a potential hire with a masters degree. When asked "What is the Rule of three?" he tried to invent something magical. That said, writing your own `vector` is not stuff you should be learning in the first week of C++. You aren't coming into programming fresh, so may I recommend supplementing your course materials with the [C++ Primer](https://www.amazon.com/Primer-5th-Stanley-B-Lippman/dp/0321714113/)? It takes a bit of time getting you up to speed on the syntax and ideologies before throwing you off the deep end.
by anonymous   2018-01-22
Is the book perhaps [C++ Primer *Plus*](https://www.amazon.com/dp/0672326973/?tag=stackoverflow17-20) by Stephen Prata? Then you *should* throw it away! See e.g. [this review](https://accu.org/index.php?module=bookreviews&func=search&rid=1744) for a few reasons why. [C++ Primer](https://www.amazon.com/dp/0321714113/?tag=stackoverflow17-20) by Stanley B. Lippman et. al. on the other hand is an *excellent* beginners book. Also see [here for a list of good beginners (and other) books](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list/388282#388282).
by parasight   2017-12-09
I'd recommend to choose one of these two books:

Programming: Principles and Practice Using C++, 2nd Ed., Bjarne Stroustrup https://www.amazon.com/Programming-Principles-Practice-Using...

C++ Primer, 5th Ed., Stanley Lippman https://www.amazon.com/Primer-5th-Stanley-B-Lippman/dp/03217...

For a very brief introduction:

A Tour of C++, Bjarne Stroustrup https://www.amazon.com/Tour-C-Depth/dp/0321958314/ref=sr_1_1...

by anonymous   2017-08-20

There are a lot of ways in C++ to achieve selection structure.

  1. if else (basically every programming language have it)

if (a)
    //do something
    //do something else
  1. switch control

switch (input)
case a:
     // do something
case b:
     // do something else
     // default when the user input is not expected a or b
  1. labels and goto keyword

int main(void)
    if (a) goto label_a;
    else if (b) goto label_b;
    goto end;
    //something else
    goto end;
    return 0;
  1. Function calls

void first() { /*something*/ }
void second() { /*something else*/ }

int main(void)
    //your previous codes
    if (a) 
        if (b)

    return 0;

More things to read: CPlusPlus Statements and Controls
Or you can invest some money to buy a good C++ Reference books like C++ Primer

by anonymous   2017-08-20

Welcome to SO.

You have really bundled two or three question together here, but lets have a go at it:

As a third component I need some kind of controlling which links the application's logic with its GUI.

Since you are using Qt, you have a built in answer to this question:

Qt Project-Model/View Programming. To get you started:

The model/view architecture

Model-View-Controller (MVC) is a design pattern originating from Smalltalk that is often used when building user interfaces. In Design Patterns, Gamma et al. write:

MVC consists of three kinds of objects. The Model is the application object, the View is its screen presentation, and the Controller defines the way the user interface reacts to user input. Before MVC, user interface designs tended to lump these objects together. MVC decouples them to increase flexibility and reuse.

If the view and the controller objects are combined, the result is the model/view architecture. This still separates the way that data is stored from the way that it is presented to the user, but provides a simpler framework based on the same principles. This separation makes it possible to display the same data in several different views, and to implement new types of views, without changing the underlying data structures. To allow flexible handling of user input, we introduce the concept of the delegate. The advantage of having a delegate in this framework is that it allows the way items of data are rendered and edited to be customized.

The MVC model, explicitly supported by the QT framework (and possible to implement with other GUI frameworks as well, albeit with more work), is widely accepted as a robust, flexible group of design patterns that affords management and separation of the various application layers, in the manner you are thinking about - so you are on the right track.

The second point may sound a little bit weird, I admit; to put it short, my aims are...

The question of how to set up your source code projects really has nothing to do with your application architecture per se, although these areas generally do intersect such that good project organization facilitates easier implementation of your architecture, and vice- versa. How you organize your project and its various libraries and classes may depend not only the project you're working on now, but on plans for future projects. For example, as you mentioned, you may want to design certain GUI components that you can use for several different applications. If so, you may want to put your GUI modules into a separate reusable generic library that can be used by many applications.

Certain rules, however are applicable across the board and are followed by most experienced developers - here are a few big ones, there are many more:

  • One major class and its friend classes per unit (hpp/cpp file).

  • Be very careful about what you include in header files and what you leave to your CPP files. You will find guidelines here on SO and in any good C++ book on this subject, which is quite important, particularly in complex projects. (From the sound of it - for example your questions about how to use #include and "connect the parts "in code - you need to get a better grasp of the some the fundamentals of C++ programming. Some excellent books are out there - you can find lists on here. C++ Primer (5th Edition) is one of the best places to start.)

  • Break down your classes and libraries in terms of their functionality. Most IDES support virtual sub-folders in your project (not sure about Code::Blocks) to help keep things organized in such manner. This actually gets into fundamental design questions, not merely how to lay out the code in your project.

  • Avoid tight coupling!

    In software engineering, coupling or dependency is the degree to which each program module relies on each one of the other modules.

    Coupling is usually contrasted with cohesion. Low coupling often correlates with high cohesion, and vice versa. Low coupling is often a sign of a well-structured computer system and a good design, and when combined with high cohesion, supports the general goals of high readability and maintainability.

  • Make good use of namespaces, another great language feature that helps keep things modularized and organized.

In your case it seems that you might want to to do is package your "application logic" into one library, your generic GUI modules into a second, and then a third, thin executable -perhaps simply containing main() and a few lines to kick things off and shut them down when done - that launches the Qt application and intializes the classes in your libraries, which interact using the the MVC model and do the actual work of the application. Three separate modules is not necessary, although it will be more "generic" and reusable" and easier to keep organized that way.

You really have touched on a wide variety of subjects with this question, and again, some of them are related to C++ programming fundamentals, not simply "separating application logic from GUI". Hopefully this answer will help get you moving in the right direction.

An important note: GUI programming is a complete and not particularly easy branch of programming. There are GUI specialists and there are programmers who work with GUI only minimally. (I'm one of the latter group). There is an SE site called User Experience which, although it doesn't deal with GUI programming per se, deals with how users interact with systems, which is directly related to GUI programming techniques. So, when you say "Now I decided to learn GUI programming", know that you are taking on a big job. If you're not really interested in making GUI programming your speciality, you might want to consider using Wizards and pre-fabricated GUI solutions instead of doing it all by hand. QtCreator does provide some such support, as does Code::Blocks. If you intend on making this serious business, there are commercial frameworks available as well. Unless you're doing it simply for the sake of learning, re-inventing the wheel is not recommended for serious commercial programming work.

by anonymous   2017-08-20

As pointed in all the comments on your question, your error occurs because you wrote your code out of a main function. Each C++ program must have it.

By the way, here are good practices for free (found also in comments).

  • Use std::array instead of C-array if you know the size at compile-time (and I believe you do).
  • Avoid using namespace std; because it's bad.
  • Be sure that you do well all your includes : #include <string>, #include <vector> and #include <array> if using-so.
  • If you're a C++ beginner, I suggest C++ Primer, updated for C++11. If your a complete beginner, Programming: Principles and Practice Using C++.
by anonymous   2017-08-20

They are the copy-constructor and the assignment operator. You should look here for information about the copy constructor, and here for information about operator overloading in general.

However, these are fundamental language constructs that should be covered in any introduction to C++. I (and many others) find that the best way to learn C++ is from a book, so I would suggest picking a beginner's C++ book and working through at least the first few chapters before anything else.