C++ Programming Tutorial

 

C# and ASP .NET

Welcome to About.com's free C++ programming tutorial. This tutorial features a series of lessons designed to teach you the basics of C++ programming

Background: History of C and C++
Before You Begin: Note to Students
Lesson 1: Hello World
Lesson 2: Variables
Lesson 3: Constants
Lesson 4: Input and Output
Lesson 5: Conditional Processing, Part 1
Lesson 6: Conditional Processing, Part 2
Lesson 7: Looping
Lesson 8: Introduction to Pointers
Lesson 9: Introduction to Classes
Lesson 10: Arrays and Vectors
Lesson 11: Strings
Lesson 12: File Input and Output
Lesson 13: References
Lesson 14: Functions, Basics
Lesson 15: Function Overloading
Lesson 16: Function Templates
Lesson 17: Classes, Members and Methods
Lesson 18: Constructors and Destructors
Lesson 19: Dynamic Memory Allocation
Lesson 20: Copy Constructors
Lesson 21: Arrays of Class Objects
Lesson 22: Mutable Members
Lesson 23: Static Members and Methods
Lesson 24: This Pointer
Lesson 25: Overloaded Operators, Part I
Lesson 26: Overloaded Operators, Part II
Lesson 27: Relationships Between Classes
Lesson 28: Scope and Lifespan
Lesson 29: Inheritance
Lesson 30: Polymorphism
Lesson 31: Multiple Inheritance
Lesson 32: Virtual Inheritance
Lesson 33: Abstract Data Types
Lesson 34: Exceptions
Lesson 35: Class Templates
 

C++ Programming Tutorial

 

About's C++ Tutorial - Lesson 1 - Hello World
The first lesson in a tutorial on C++ programming. Covers some basic terminology and presents a simple program.
About's C++ Tutorial - Lesson 2 - Variables
A lesson on the declaration and use of variables in C++ programming. Covers names and data types.
About's C++ Tutorial - Lesson 3 - Constants
A lesson on the declaration and use of constants in C++ programming.
About's C++ Tutorial - Lesson 4 - Input and Output
A lesson on input and output in C++ programming. This lesson also introduces the string class.
About's C++ Tutorial - Lesson 5 - Conditional Processing I
A lesson on conditional processing using if and else statements. This lesson also covers relational operators.
About's C++ Tutorial - Lesson 6 - Conditional Processing II
A lesson on conditional processing using switch statements. This lesson also covers logical operators.
About's C++ Tutorial - Lesson 7 - Looping
This lesson introduces three constructs used to implement loops in C++: do, for and while.
About's C++ Tutorial - Lesson 8 - Introduction to Pointers
This lesson introduces the concepts and uses of pointers in C++.
About's C++ Tutorial - Lesson 9 - Introduction to Classes
An overview of building and using classes in C++. This lesson also introduces some terminology commonly used in object-oriented programming.
About's C++ Tutorial - Lesson 10 - Arrays and Vectors
A lesson on declaring and using arrays in C++. The relationship between pointers and arrays is also discussed. The vector container class, which is part of the C++ standard library, is also discussed. The generic algorithms, which are part of the C++ standard library, are introduced. These algorithms provide useful manipulations of the container classes and the built-in array type.
About's C++ Tutorial - Lesson 11 - Strings
This lesson covers stings. C++ has two methods for representing strings, C-style character arrays and the string class. C-style character arrays are a low-level, primitive representation of string data. The string class provides more functionality and is less error prone in use. It provides methods for easy manipulation of string data.
About's C++ Tutorial - Lesson 12 - File Input and Output
This lesson covers file input and output, and iostream manipulators. Learning how to read and write files is an important step in learning any programming language. Also, covers output formatting and iostream operators.
About's C++ Tutorial - Lesson 13 - References
In C++, a reference is an alias to a variable. The real usefulness of references is when they are used to pass values into and return values from functions. This lesson shows how to create and use references.
About's C++ Tutorial - Lesson 14 - Functions, Basics
This lesson covers declaring and defining functions, using functions, returning multiple values, passing arrays to functions and default parameters. Functions are used to encapsulate a set of operations and return information to the main program or calling routine.
About's C++ Tutorial - Lesson 15 - Function Overloading
This lesson covers overloaded functions. Function overloading provides a way to have multiple functions with the same name, provided each differs in the number or type of its parameters.
About's C++ Tutorial - Lesson 16 - Function Templates
This lesson covers function templates. Function templates provide a way to parameterize the arguments or return types of a function. What does this mean? In the definition of the function, rather than specifying an explicit type of some of the arguments or the return value, a placeholder is used. This allows one function definition to work for multiple data types.
About's C++ Tutorial - Lesson 17 - Classes, Members, Methods
The use of objects in C++ defines the way programs are designed and written. Classes are a software construct that can be used to emulate a real world object. This lesson is the first of several that will teach all you need to know to define and use classes and objects in C++.
About's C++ Tutorial - Lesson 18 - Constructors/Destructors
This lesson covers constructors and destructors. A constructor is called whenever an object is created. It is used to initialize data members. A destructor is called whenever an object goes out of scope or is deleted.
About's C++ Tutorial - Lesson 19 - Memory Allocation
This lesson covers dynamic memory allocation in C++ using the new and delete operators. Dynamic allocation of objects is useful whenever the exact size or number of objects cannot be determined until program execution. Techniques to avoid two common programming bugs, memory leaks and dangling pointers, are described.
About's C++ Tutorial - Lesson 20 - Copy Constructors
This lesson is covers copy constructors. A copy constructor is a special constructor that takes as its argument a reference to an object of the same class and creates a new object that is a copy. Learn about shallow and deep copies of objects.
About's C++ Tutorial - Lesson 21 - Arrays of Class Objects
Previous lessons covered creating arrays and single objects of automatic extent and dynamically allocating arrays and single objects for objects of built-in types. This lesson extends these concepts to include creating and using arrays of class objects.
About's C++ Tutorial - Lesson 22 - Mutable Members
This lesson deals with two important keywords, const and mutable, and their use with class objects.
About's C++ Tutorial - Lesson 23 - Static Members / Methods
This lesson covers static class members and methods. Static members provide a way to create objects that are shared by an entire class, rather than being part of a particular instance of the class, an object.
About's C++ Tutorial - Lesson 24 - This Pointer
This lesson covers the purpose and use of the "this" pointer. In addition to the explicit parameters in their argument lists, every class member function (method) receives an additional hidden parameter, the "this" pointer.
About's C++ Tutorial - Lesson 25 - Operator Overloading I
This lesson covers the topic of operator overloading. Operator overloading provides a way to define and use operators such as +, -, *, /, and [] for user defined types such as classes and enumerations.
About's C++ Tutorial - Lesson 26 - Operator Overloading II
This is the second part of a lesson on operator overloading. It presents some general rules, operators in global and namespace scope and the concept of friend functions.
About's C++ Tutorial - Lesson 27 - Class Relationships
For an object-oriented language, such as C++, program design starts with choosing classes and defining their relationships. The three main types of relationships between classes are generalization (inheritance), aggregation, and association.
About's C++ Tutorial - Lesson 28 - Scope and Lifespan
This lesson covers the topics of variable scope and lifetime.
About's C++ Tutorial - Lesson 29 - Inheritance
In C++, inheritance defines an "is a" relationship. The derived class is a type of its base class. For instance, a "cat" class could be derived from an "animal" class. Derived classes can inherit both methods and members from base classes
About's C++ Tutorial - Lesson 30 - Polymorphism
This lesson covers polymorphism and virtual methods. Polymorphism in C++ is exhibited by the ability of a pointer or reference to a base class type to behave in different ways when it is used to manipulate objects of different subtypes of that base class.
About's C++ Tutorial - Lesson 31 - Multiple Inheritance
This lesson covers multiple inheritance. In C++, a class may have multiple base classes. That is, it may inherit the members and methods of multiple base classes. Percolating up, casting down and Runtime Type Identification (RTTI) are covered. The lesson includes instructions on activating RTTI in VC++ 6.0 and VC++.net.
About's C++ Tutorial - Lesson 32 - Virtual Inheritance
This lesson covers some ambiguities that can arise with multiple inheritance, and their solutions, including virtual inheritance.
About's C++ Tutorial - Lesson 33 - Abstract Data Types
This lesson covers abstract data types and pure virtual functions. An abstract data type is a class that is meant to serve only as an interface for derived classes; it cannot be instantiated.
About's C++ Tutorial - Lesson 34 - Exceptions
This lesson covers exceptions. Exceptions are errors or anomalies that occur during the execution of a program. Learn how they are handled in C++.
About's C++ Tutorial - Lesson 35 - Class Templates
This lesson is an introduction to class templates. Class templates provide a way to parameterize the types within a class. This means that rather than explicitly specifying the data type associated with a class member or method, a placeholder is used. When we instantiate an instance of the class, the actual data type is substituted for the parameter, or placeholder.