C-CAT C++ and OOP Revision: Concepts and Traps
C++ and OOP for C-CAT
C++ questions test the object-oriented ideas and a few language rules. Most are either definitions or short snippets whose output depends on a single rule, such as the order in which constructors run.
Topic checklist
| Topic | Be able to |
|---|---|
| OOP principles | Encapsulation, abstraction, inheritance, polymorphism |
| Classes and objects | Access specifiers, member functions, this pointer |
| Constructors | Default, parameterised, copy; initialiser lists |
| Destructors | When called, and why they should be virtual in a base class |
| Inheritance | Types, access in derived classes, diamond problem |
| Polymorphism | Overloading, overriding, virtual functions, pure virtual |
| Operators | Overloading rules and which operators cannot be overloaded |
| References and memory | Reference vs pointer, new and delete |
| Templates and exceptions | Function and class templates, try, catch, throw |
Classes, objects and access
- Class members are private by default; struct members are public.
- A derived class can access public and protected members of its base, but never private ones.
- A friend function can access private members but is not a member of the class.
- A static member belongs to the class and is shared by all objects.
- The
thispointer points to the object a member function is called on.
Constructors and destructors
- A constructor has the class name and no return type. If you write none, the compiler provides a default constructor, but not if you write any other constructor.
- The copy constructor runs when an object is created from another object, passed by value or returned by value.
- Constructors run base to derived. Destructors run derived to base.
- Members are initialised in the order they are declared, not the order in the initialiser list.
- If a base class pointer deletes a derived object and the base destructor is not virtual, the derived destructor does not run, which is undefined behaviour.
Inheritance
| Type | Meaning |
|---|---|
| Single | One base, one derived |
| Multiple | Derived from more than one base |
| Multilevel | A chain of derived classes |
| Hierarchical | Many classes derived from one base |
| Hybrid | A combination of the above |
With public inheritance, public stays public and protected stays protected. With private inheritance, both become private in the derived class.
The diamond problem occurs when two base classes share a common base. Virtual inheritance keeps a single copy of that common base.
Polymorphism and virtual functions
- Compile-time polymorphism: function overloading and operator overloading.
- Run-time polymorphism: function overriding with virtual functions.
- A call through a base pointer runs the derived version only if the function is
virtual; otherwise the base version runs. - A pure virtual function is declared with
= 0. A class with at least one is abstract and cannot be instantiated. - Constructors cannot be virtual. Destructors can and often should be.
- Overloaded functions must differ in their parameters; they cannot differ only in return type.
Operator overloading
- Operators that cannot be overloaded:
::,.,.*,?:andsizeof. - At least one operand of an overloaded operator must be a user-defined type.
- Overloading does not change precedence or associativity.
=,[],()and->must be overloaded as member functions.
References, pointers and memory
- A reference is an alias. It must be initialised when declared and cannot be reseated to another variable.
- A pointer can be null and can be reassigned; a reference cannot.
newallocates memory and calls the constructor;deletecalls the destructor and frees the memory. Usedelete[]for arrays created withnew[].- Memory from
newmust not be freed withfree, and the reverse.
Templates and exceptions
- A template lets one function or class work with many types:
template <typename T>. - Exceptions use
try,throwandcatch. The matchingcatchblock runs, and stack unwinding destroys local objects on the way. - Put
catchblocks for derived exception types before those for base types.
Revise and practise
- OOP & C++ Cheat Sheet for one-page revision
- OOP with C++ MCQs: 69-question practice set
- OOP & C++ MCQs for a shorter concept check
- OOP & C++ Flashcards to test recall
- Introduction to OOPs in C++ for detailed notes
- C-CAT Section B Preparation Guide for the overall checklist
- C++ Revision for CMCE: PGCP-AC Notes for long-form notes with lab programs
- C-CAT syllabus for the full topic list
Key takeaways
- Know constructor and destructor order; it decides many outputs.
- Virtual functions only change behaviour through a base pointer or reference.
- Remember what cannot be overloaded and what cannot be virtual.
- Practise mixed snippets, not only definitions.
Frequently Asked Questions
1 Which C++ topics matter most for C-CAT?
Classes and objects, constructors and destructors, inheritance, polymorphism with virtual functions, operator overloading, references versus pointers, and basic templates and exceptions.
2 What is the difference between a class and a struct in C++?
The only language-level difference is the default access: members of a class are private by default, and members of a struct are public by default. Both can have functions, constructors and inheritance.
3 What is a virtual function?
A virtual function is a member function that is resolved at run time based on the actual object type when called through a base class pointer or reference. This is how run-time polymorphism works in C++.
4 In what order are constructors and destructors called?
Constructors run from base to derived, and destructors run in the reverse order, from derived to base. Members are constructed in the order they are declared in the class.
5 How should I practise C++ for C-CAT?
Revise each concept, then solve output-prediction questions that mix constructors, inheritance and virtual functions. Work through MCQs and read every explanation.