The C++ Programming Language, 4th Edition
All
Stack Overflow 10
This Year
Stack Overflow 2
This Month
Reddit 2
The C++ Programming Language & Effective Modern C++
YES ITS FREE!!
Here is the sort of path I took, gonna leave out out my short affair with C# because it honestly didnt contribute much to my learning.
Khan academy programming tutorials. Hit all the basics and finish up the Object Oriented section. This will give you a solid footing as really all you need to be learning at this point is flow control and the basics of object oriented programming.
From here, id recommend Python. Although I personally dislike Python, the environment is great and writing in it feels similar to just talking out loud - very smooth. The language is slow and extremely high level (meaning you dont have a ton of control), but its so imporant that you actually get your head around working with other people's APIs and get you started on how to structure a program.
From there its really up to you. If you feel like you are ready to take the dive and hop into some tricky stuff, C++ is IMO amazing, but it gets plenty of hate as poorly writin code has consequences and the language is a bir massive.
For those out there wanting to learn C++ eventually, I recommend this book over C++ 11 although I think a newer edition is out. I read that book almost religiously and tried applying as much as possible. Took me from writing crappy code to decent code. The beautiful website stack overflow is your best buddy for problem solving, it is also a great way to get introduced to new features as C++ is huge and no one source will show you everything (plenty of it is redundant anyways). Google is your best friend with sites like c++ docs giving you a much deeper look into a feature.
The only language ive gotten into any real depth with is C++; but I imagine a good book, stack overflow, and online docs will do the trick.
You are (probably) going to screw up many many times before you right solid code no matter the language. Just dont give up and keep going! The best way to learn when it comes to this stuff is doing!
Most of programming is just architecture, and its something you can only learn through doing.
If you need help in the future, or anyone else for that matter, feel free to PM me, id be glad to help.
Using Visual Studio with C++ is trivial, just open the "Get tools and packages" window and install the C++ desktop development package, then start with one of the templates MS provides.
Bjarne's book is a good C++ beginner resource:
https://www.amazon.com/C-Programming-Language-4th/dp/0321563840
One you know what you're doing somewhat, this is a good resource for best practices:
http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines
But personally I'd start by limiting yourself to C (or the C subset of C++) first, and wrapping your head around the basics of low-level programming (like pointers) before taking on C++. It's a big, ugly language that will hurt your brain (and honestly, it would not be my first choice for anything that doesn't require its particular properties - what are you planning to do with it?).
>Someone might recommend better but The C++ Programming Language has been well received as a modern introductory C++ book.
​
That book is a reference book; it would be like trying to learn a language to by reading a dictionary. Perhaps you are thinking of Bjarne's "Programming: Principles and Practice Using C++" (his textbook for an intro to programming class), or his "A Tour of C++" (which is targeted to experienced programmers who wish to learn C++).
"Programming: Principles and Practice Using C++" is great because it teaches with modern C++.
Someone might recommend better but The C++ Programming Language has been well received as a modern introductory C++ book. You might want to consider starting with that. Also, picking an IDE can make life easy, but isn't a requirement. Of the IDEs to choose from: CLion is popular but costs. I think Visual Studio is popular, but I believe it costs too (Not to be mistaken with VS Code). Qt Creator is pretty popular as is KDevelop. Both are free.
Read The C++ Programming Language https://www.amazon.fr/dp/0321563840/ref=cm_sw_r_cp_apa_i_cIRHCbGP6565K
Get a Raspberry Pi 2 Model B Starter Kit (Raspberry Pi 2 Model B UK Version, 8GB microSDHC Class 10, 2000mA MAREL power plug, black OneNineDesign case) https://www.amazon.fr/dp/B013PIVKVG/ref=cm_sw_r_cp_apa_i_iLRHCb5GS1JJM
Install linux on it (you will have gcc C++ compiler and plenty of stuff) and that s your own computer.
Well, just for reference, I think The C++ Programming Language by C++'s author is a really good way to start. If you want to practice your problem solving skill alongside with your C++ skill, CodeSignal may help you.
Actually, it is better if you work on some projects, you will learn a lot.
In your tree constructor, you need to initialize the root pointer to NULL. It's not guaranteed to be initialized as NULL.
When you compile in linux, you can use gdb to show where the source of the segfault is coming from.
Some other notes:
root
after you've allocated the new node. You're not doing that because you're missing one of the fundamentals of c++. That is, it's based on c. And the thing about c is that is strictly a "by-value" function/method calling paradigm. So all parameters in a function call are by value. When you pass in the memory address for root, you're actually copying the value of the pointer. Then, you're only updating the local value. You need to assign it back to root. If you'd like to learn that concept front to back, I highly recommend watching Jerry Cain's Programming Paradigms course at Stanford.this->root
andthis->insert
notation. Not only will it correctly resolve if you accidentally create a locally scopedroot
variable, but it's also clearer to the reader where the data or method is defined. Great coding is about communication. It may only take 100-500ms less for the reader to understand where the symbol points to; however, the tiny savings that you can accumulate in avoiding ambiguities add up into a much clearer piece of software. Your future self (and your colleagues) will thank you. See http://msmvps.com/blogs/jon_skeet/archive/2013/09/21/career-and-skills-advice.aspxLastly, I can overstate enough how important learning from the source is. If you're learning c or c++ for the first time, read http://www.amazon.com/The-Programming-Language-4th-Edition/dp/0321563840 and http://www.amazon.com/Programming-Language-2nd-Brian-Kernighan/dp/0131103628. It will save you hours, upon hours, upon hours. After having learned from the source, programming is also A LOT more enjoyable because you understand a good portion of the concepts. And, the truth is, things are more fun when you have a decent level of competence in them.
The 4th edition of the best C++ book has been just published: The C++ Programming Language, 4th Edition. It contains all the new techniques as well as the new C++11 standard.
To start with Bjarne Stroustrup in his 4th edition of his seminal book "The C++ Programming Language" doesn't refer to the use of
auto
as rendered in your code example. But rather to the standard use of theauto
specifier as:auto i = 0;
).Specifier for function's return type where it's going to be deduced by its trailing return type or from its return statement.
auto foo(int a, int b) {return a + b; }
In your example you're referring to the use of
auto
as a placeholder as suggested by C++ extensions for Concepts (N4674) proposal. Unfortunately, this is not standard C++ yet. It was to be accepted in C++17 but it didn't make it. Hopes now rise for C++20. However, use ofauto
like that is provided by GCC as an extension. Work on C++ concepts for GCC started very early, it even predates the advent of C++11. At some point work on concepts was abandoned and then restarted under another name namely Concepts Lite. Support back then was pretty unstable (e.g., GCC version 5.4). Thus, what you're experiencing is a GCC bug. In more recent versions of GCC this bug has been corrected.K&R and Stroustrup are classics, and eventually you should get them, but I don't think they are good introduction for C++ beginners. Thinking in modern C++ is thinking in classes, templates, exceptions, and streams, none of which available in C language.
I would recommend a college-level textbook on C++ like Deitel and Deitel. alt text http://ecx.images-amazon.com/images/I/61dECNkdnTL._SL500_AA240_.jpg
After playing around, you should focus on learning to write a class that behaves like a built-in class. That means providing a copy constructor,
operator=
,operator==
,operator<<
, etc.. Along the way you'll meet various concepts embedded in the language of C++. I would agree with others on Effective C++ is a must read once you are comfortable with the basics.The short version:
In COM you should use
HRESULT
s (and strive to useISupportErrorInfo
, etc.) for most/all types of error conditions. TheHRESULT
mechanism should be viewed as a form of exception throwing. If you are familiar with that, consider "Error conditions" as anything for which you would normally throw an exception in a language that supports them. Use custom return values for things for which you would not normally use exceptions.For example, use a failure HRESULT for invalid parameters, invalid sequence of operations, network failures, database errors, unexpected conditions such as out-of-memory, etc. On the other hand, use custom out parameters for things like 'polling, data is not ready yet', EOF conditions, maybe 'checked data and it doesn't pass validations'. There is plenty of discussions out there discussing what each should be (e.g. Stroustrup's TC++PL). The specifics will heavily depend on your particular object's semantics.
The longer version:
At a fundamental level, the COM HRESULT mechanism is just an error code mechanism which has been standardized by the infrastructure. This is mostly because COM must support a number of features such as inter-process (DCOM) and inter-threaded (Apartments) execution, system managed services (COM+), etc. The infrastructure has a need to know when something has failed, and it has a need to communicate to both sides its own infrastructure-related errors. Everybody needs to agree on how to communicate errors.
Each language and programmer has a choice of how to present or handle those errors. In C++, we typically handle the HRESULTs as error codes (although you can translate them into exceptions if you prefer error handling that way). In .NET languages, failure HRESULTs are translated into exceptions because that's the preferred error mechanism in .NET.
VB6 supports "either". Now, I know VB6's so-called exception handling has a painful syntax and limited scoping options for handlers, but you don't have to use it if you don't want to. You can always use
ON ERROR RESUME NEXT
and do it by hand if you think the usage pattern justifies it in a specific situation. It's just that instead of writing something like this:Your write it like this:
VB6 is simply hiding the error code return value from the method call (and allowing the object's programmer to substitute it for a "virtual return value" via
[retval]
).If you make up your own error reporting mechanism instead of using
HRESULT
s, you will:One of the best explanation of
lambda expression
is given from author of C++ Bjarne Stroustrup in his book***The C++ Programming Language***
chapter 11 (ISBN-13: 978-0321563842):What is a lambda expression?
When would I use one?
What class of problem do they solve that wasn't possible prior to their introduction?
Here i guess every action done with lambda expression can be solved without them, but with much more code and much bigger complexity. Lambda expression this is the way of optimization for your code and a way of making it more attractive. As sad by Stroustup :
Some examples
via lambda expression
or via function
or even
if u need u can name
lambda expression
like below:Or assume another simple sample
will generate next
[]
- this is capture list orlambda introducer
: iflambdas
require no access to their local environment we can use it.Quote from book:
Additional
Lambda expression
formatAdditional references:
Unfortunately, no such function exists in the C++ standard library.
If you do have access to Boost, then
boost::numeric_cast
should do exactly what you want. It will perform a conversion between two numeric types unless the conversion would go outside the range of the target type. In such cases, aboost::numeric::bad_numeric_cast
exception is thrown.If you were curious about implementing your own conversion, you can take a look at The C++ Programming Language 4th Edition by Bjarne Stroustrup (ISBN 978-0321563842).
In Chapter 11.5, he defines a
narrow_cast
as such:This implementation is quite bare and doesn't go quite as far as Boost's does, but could conceivably be modified to suit your needs.