Learn By Example: C++ Programming - 75 Solved Problems
4.2 (160 ratings)
Instead of using a simple lifetime average, Udemy calculates a course's star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.
2,806 students enrolled
Wishlisted Wishlist

Please confirm that you want to add Learn By Example: C++ Programming - 75 Solved Problems to your Wishlist.

Add to Wishlist

Learn By Example: C++ Programming - 75 Solved Problems

C++ will never seem intimidating again, once you're done with these examples.
4.2 (160 ratings)
Instead of using a simple lifetime average, Udemy calculates a course's star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.
2,806 students enrolled
Created by Loony Corn
Last updated 9/2016
Curiosity Sale
Current price: $10 Original price: $50 Discount: 80% off
30-Day Money-Back Guarantee
  • 16 hours on-demand video
  • 171 Supplemental Resources
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of Completion
What Will I Learn?
  • Harness the full power of C++ without being intimidated by the language's complexities
  • Use inheritance, operator overloading, templates, STL and all major C++ language features
View Curriculum
  • Students should have an understanding of programming - concepts such as variables, loops and if-else statements will not be explained

Like a gruff uncle, C++ seems intimidating, when its just being helpful. These 75 examples will help you understand that.

Let's parse that.

  • C++ seems intimidating because all too often, what you see is not what you get.
  • Usually, that's because C++ is trying to help you, but you don't realise that. C++ is incredibly deep, and it sometimes struggles to get you - the programmer - to understand what it's saying
  • These 75 examples will help. Each is self-contained, has its source code attached, and gets across a specific C++ use-case. Each example is simple, but not simplistic.

What's Included:

  • Moving to C++ from C: If you are a C programmer, this section will run through what you need to know in order to move seamlessly to C++.
  • Objects, Classes and Object-Oriented Programming: Access modifiers, classes, objects, the this pointer, new/delete and dynamic memory allocation gotchas
  • Operator overloading is a particularly complicated topic - C++ is virtually alone in the ubiquity of overloaded operators. Make sure this doesn't trip you up. Also go deep into the workings of const, static and friend
  • Inheritance in C++ is considerably more complicated than in Java, mostly because of multiple inheritance, and because of the co-existence of both virtual and non-virtual methods.
  • Templates are a classic generic programming technique that were revolutionary when first added to C++. Understand template functions and classes, as well as template specializations.
  • STL - the Standard Template Library - is incredibly powerful. Get a good sense of collections, iterators and algorithms - the major components of the STL
  • C++ casts are quite different than C-casts. Understand const_cast, static_cast and dynamic_cast, as well as Real Time Type Identification (RTTI), and the manner in which explicit conversions can be performed using static_cast
  • Exceptions and exception handling in C++

Using discussion forums

Please use the discussion forums on this course to engage with other students and to help each other out. Unfortunately, much as we would like to, it is not possible for us at Loonycorn to respond to individual questions from students:-(

We're super small and self-funded with only 2 people developing technical video content. Our mission is to make high-quality courses available at super low prices.

The only way to keep our prices this low is to *NOT offer additional technical support over email or in-person*. The truth is, direct support is hugely expensive and just does not scale.

We understand that this is not ideal and that a lot of students might benefit from this additional support. Hiring resources for additional support would make our offering much more expensive, thus defeating our original purpose.

It is a hard trade-off.

Thank you for your patience and understanding!

Who is the target audience?
  • Yep! Java and C# programmers - who understand Object Oriented Programming, but are new to C++
  • Yep! Folks with prior programming experience in C. No prior object oriented programming experience is needed
Students Who Viewed This Course Also Viewed
Curriculum For This Course
87 Lectures
Introducing C++
1 Lecture 02:19

C++ should be fascinating - all too often, it comes across as intimidating instead. But there is no reason for this to be the case! By the time you are done with this class, you too will come to like and appreciate C++ for its elegance and power.

Preview 02:19
Moving from C to C++
6 Lectures 01:20:57

C++ is an ocean and C is a very small river which feeds into that ocean. C is the foundation on which C++ is built, let's see the differences between C and C++ in a very simple program. This is a taste of things to come.

C and C++ - similar in some ways but actually very different

A class is a user-defined type - a template for creating variables.

C vs C++: Comments are different - and oh C++ has namespaces!

Variables with the same name can be defined in different scopes. Accessing them requires the use of the scope resolution operator. This becomes super useful once we get to classes!

Preview 09:08

C++ allows multiple functions with the same name but different signatures. Things get even more hardcore. You can overload common operators such as +. -. *, /. [] etc to work with your own objects. Here is a sneak peak into these constructs.

Not just function overloading, C++ allows operator overloading as well!

C++ allows you to specify meaningful default values for function arguments. But once you bring overloaded functions into the mix things can get pretty complicated. Some do's and don'ts of working with default values passed to functions.

Default Values

References are pointers in disguise and so easy to use! Const prevents accidental modifications of variables and the bool keyword makes the boolean a first class citizen along with ints, floats etc.

A sneak peak into these before we cover them in more detail later.

References, Const and Bool
Objects and Classes
6 Lectures 01:39:17

A C programmer might call a class a "struct with functions". This is a brief introduction to the basic ideas on which Object Oriented Programming is built.

Classes mean different things to different people!

A class is a logical component. It holds data and functions of a specific entity.

Classes - A logical grouping of data and functions

Set up your very first C++ class! An object is a variable of a class. Repeat that, remember that.

Example 1 and 2: Define a really simple C++ class and instantiate it

Invoke just means call a member function!

Example 3: Invoke the member functions of an object

Constructors help setup and initialize objects of classes and destructors help clean up when these objects go out of scope. Destructors are especially useful when your class references resources which need clean up, like file handles or pointers.

Example 4 and 5: Setup and clean up using constructors and destructors

Member variables and functions can be marked public, private or protected. Understand what those terms mean.

Preview 19:36
Multi-file Programs
2 Lectures 33:03

There are excellent reasons to separate declarations (.h files) and definitions (.cpp files). Let's understand why this usually makes sense in real-world projects, and how to do this right.

Preview 16:02

Let's see a real live example of how multiple files would be set up and used in production code.

Preview 17:01
Dynamic Memory Allocation: new and delete
7 Lectures 01:27:33

Let's go back and brush up on what dynamic memory allocation is.

Dynamic Memory Allocation

Dynamic memory allocation is quite different in C++ than in C (or in Java, for that matter). Here are a few rules which should help keep you on the right path while using the new and delete keywords.

C++ memory allocation explained

Never use malloc or free in C++. Ever.

Use new to allocate and construct objects and delete to deallocate memory and destruct objects. Use the array variants where needed. The "new" keyword pairs with "delete" and "new[]" pairs with "delete[]".

Stop using malloc and free

new does more than simply allocate memory - it calls the constructor. delete does more than deallocate memory - it calls the destructor. new[] and delete[] operate on arrays - they painstakingly go through an array and do their thing, element-by-element.

So not mix-n-match the two!

Remember to clean up the variables in your class in the destructor.

Do not mix new/delete for single variables with array equivalents new[]/delete[]

Using malloc will allocate memory but not call the constructor. Using free will deallocate memory but not call the destructor. Not good.

See how nicely new and delete play with objects!

Example 8 and 9: Stop using malloc and free, use new and delete instead!

Construct and destruct arrays using new[] and delete[]. new/delete expects a single element, new[]/delete[] expects an array. The two forms won't mix.

Example 10 and 11: Use new[] and delete [] for arrays - never mix new and new[]

An arcane C++ operator - use this when you need to specify upfront where your object should reside.

Every object knows itself. How? Because the C++ compiler injects a special pointer called the this pointer.

Preview 17:06
The C++ string Class
6 Lectures 40:41

The C++ string class is so much cooler than the C char* type.

The C++ string class

Simple string operations

Example 14: Strings

Inputting a string with line breaks or spaces requires a special function called getline. Understand how to use this.

Preview 05:45

The set of operations we need to perform on strings is not that complicated in C++

Example 16: More common string operations

Compare strings as if they were numbers.

Example 17: Comparing strings

Its really easy. Enough said.

Example 18: Converting C++ to C strings (and vice versa)
4 Lectures 47:53

References are pointers, but they pretend that they aren't. Working with references correctly require you to follow a whole bunch of rules - here they are in all their glory!

The basic idea of references

Create a simple reference variable and learn how to use them.

const references have some little nuances of their own.

Two ways to swap integers, the heavyweight C style vs the nifty C++ style.

Example 19, 20 and 21: A simple reference, a const reference, and C++ swap

References must be initialised - there is no way around that.

You might think you're reassigning a reference, but you might be doing something different.

If you have multiple references and variables pointing to the same data, one change will change them all.

Technically, a reference can never hold a null value. But if you try really hard, you can slide one by.

Preview 14:55

References to pointers: Just remember to free and delete the underlying pointers as usual.

References to references: The C++ standard prohibits references to references, or arrays of references.

References as return types: Its hard trying to return a reference from a function. If its a heap variable, who will deallocate it?

References to stack variables: Its hard trying to return a reference from a function. If its a stack variable, it will cease to exist before you can use it!

Example 26, 27, 28, 29: References to pointers, references as return types
The const Keyword
5 Lectures 01:11:06

The const keyword is really powerful, and really subtle.

Define a const variable, see how it works.

The C++ compiler can guarantee bitwise constness, not semantic constness, understand what that means.

Example 30 and 31: The C++ const keyword

This is a popular interview question, so make sure you understand this one!

Preview 16:44

Const member functions: A member function can be marked const. That's a way of saying that it won't modify the object. It can't call any non-const functions, or modify any member variables of course.

Mutable variables: If you mark a member variable as mutable, a const method can change its value.

Overloading functions on const: This is something you will use surprisingly often.

const_cast: There's a backdoor way to get rid of constness.

Example 33, 34, 35, 36: Const methods, mutable, overloading on const, const_cast

Try and pass function parameters as const references, not by value. There are performance reasons for it, that we discuss here. There is also another reason - to avoid object slicing - that we will talk about later.

Passing function parameters const references

Try and pass function parameters as const references, not by value. There are performance reasons for it, that we discuss here. There is also another reason - to avoid object slicing - that we will talk about later.

Let's now see an example of this!

Example 37: Passing function parameters const references
The static Keyword
4 Lectures 39:57

In C, static is a storage class. In C++, it is something different.

The basic idea of static in C++

Are shared by all objects of a class (unlike member variables, which are 1-per-object). The process for defining static member variables is kinda nasty. Make sure you understand it.

Example 38: Static member variables

These are member functions which are called on a class not an object. They can only access static member variables!

Example 39 and 40: Static member functions

These have a twist - they need an in-class definition, and then a dummy definition outside. Oh well.

Preview 06:57
The friend Keyword
3 Lectures 36:49

Jokes abound - but the idea has its uses, as we will see when we get to operator overloading.

The basic idea of friends in C++

Friends can be either functions or classes - here we learn about friend functions

Example 42: Friend functions

When you declare a class to be your friend, all of its member variables become your friends in the bargain.

Preview 07:08
6 More Sections
About the Instructor
Loony Corn
4.3 Average rating
5,043 Reviews
39,290 Students
76 Courses
An ex-Google, Stanford and Flipkart team

Loonycorn is us, Janani Ravi and Vitthal Srinivasan. Between us, we have studied at Stanford, been admitted to IIM Ahmedabad and have spent years  working in tech, in the Bay Area, New York, Singapore and Bangalore.

Janani: 7 years at Google (New York, Singapore); Studied at Stanford; also worked at Flipkart and Microsoft

Vitthal: Also Google (Singapore) and studied at Stanford; Flipkart, Credit Suisse and INSEAD too

We think we might have hit upon a neat way of teaching complicated tech courses in a funny, practical, engaging way, which is why we are so excited to be here on Udemy!

We hope you will try our offerings, and think you'll like them :-)