Understanding RAII: A Guide for C++ Developers

Acronyms, like RAII (Resource Acquisition Is Initialization), can be intimidating for programmers but reveal their elegance once understood. RAII ties resource management to object lifetime, ensuring reliable cleanup even during exceptions. This blog illustrates its significance through examples, emphasizing its role in modern C++ and urging developers to adopt its principles.

Chapter 7 : Class Template Instantiation

In this chapter, we will learn various aspects of class template instantiation. Understanding the class template instantiation is pivotal to the overall understanding of the functioning of templates in general. The fundamental concept of template instantiation remains the same for both function templates and class templates. However, instantiation of class template instantiation is more complex than function template.

Mastering Function and Class Templates in C++: A Complete Guide

The content outlines seven chapters on C++ templates, covering introductory concepts, function templates, template parameters, return types, miscellaneous aspects, class templates, and class template instantiation. Each chapter provides a foundation for understanding and effectively using templates in C++. Additionally, it mentions the availability of source code.

Mastering Templates in C++: A Comprehensive Guide

C++ templates are a powerful tool for writing flexible and reusable code, enabling type-independent programming. This guide covers everything from basic template syntax to advanced concepts like class templates, function return types, and instantiation. Whether you're new to templates or looking to refine your skills, each chapter provides clear explanations and practical insights. Dive in and unlock the full potential of C++ templates to write more efficient and scalable programs.

Chapter 6 : Working with Class Templates

In the first section of the book, we have learned about the basic syntax and usage of a function template. In this second part of the book, we will focus on the class templates. Class templates are an essential tool for the programmer to design classes that can work on the generic data type. While class templates are an excellent tool for the programmers, it is slightly complex than the function templates. The syntax and usage may look a bit daunting for new programmers. In this chapter, we will learn about how to declare and define classes with templated parameters step by step with simple examples at each step.

Chapter 5 : Miscellaneous template aspects

In this chapter we will cover the following topics - Understanding difference between declaration and definition, Compiling and linking of template function, Organizing template function code, Abbreviated function templates, Overloading template function.

Chapter 4 : Return type of template function in C++

This chapter will discuss the various ways we can declare or deduce the return type of a template function. We can use either template or non-template parameters to declare the return type of a function template. We can also deduce the return type using keywords like auto and decltype. In some cases, we can declare a separate type parameter for the return type. Because of these intricacies, it is necessary to discuss the template function’s return type in detail with specific examples tailored for each case.

Chapter 3 : All about Template Parameters in C++

In the previous chapter, we learned all about function templates. While learning about function templates, we came across the terminology template parameter. In this chapter,…

Continue reading → Chapter 3 : All about Template Parameters in C++

Chapter 2 : Working with Function Templates in C++

In the previous chapter, we had a brief encounter with function templates. In this chapter, we will learn how to implement a function template. We…

Continue reading → Chapter 2 : Working with Function Templates in C++

Chapter 1 : Introduction to Templates in C++

C++ templates are intimidating for any beginner or intermediate level programmer as it is syntactically a bit cryptic and complex. Also, there are intricacies in how to use the powerful features of the language. A standard C++ book does not always go into the feature’s details instead of just touching upon the subject, which is not sufficiently explanatory for the first-time learners. Sometimes the examples are too complicated, or the explanations are too vague to understand. Often, there are not many different sample codes to practice enough to have a good grip on the subject. In other cases, the available books go so deep into the nitty-gritty of the language that the reader feels a bit lost in the sea of information. In either way, the subject seems daunting for the newbies or intermediate-level programmers. However, if we explain it systematically with simple examples and easy-to-understand explanations, the C++ template could be a powerful tool for programmers. Proper use of templates can lead to clean, elegant, and efficient code on many occasions. The reader should be a beginner or intermediate-level programmer who has a basic understanding of C++ programming. They do not need to have detailed, in-depth knowledge or vast experience on the subject but should be familiar with the C++ programming paradigm’s basic concepts and be looking to take it to the next level.

C++ notes: Shallow copy, overloaded assignment operator and deep copy explained

Operator overloading is one of the fundamental operation which come across often in a C++ program. It is bit cryptic in syntactical side as well as often a misunderstood topic amongst new programmer. I will try to explain this as a series of C++ related notes (as I like to call this) following this post.

Customizing Qt Creator 5.12.4

Install the custom Toolchain Download and install the toolchain rpm sudo alien ~/Downloads/<toolchain-name>.rpm sudo dpkg -i ./<toolchain-name>.deb Locate the arm compiler sudo find / -iname…

Continue reading → Customizing Qt Creator 5.12.4

How to create and run cppcheck executable from source code in linux machine (C++11 Static Analysis)

I do not have administrative rights on a linux server (openSuse Linux) I am working on right now. So installing anything is not an option…

Continue reading → How to create and run cppcheck executable from source code in linux machine (C++11 Static Analysis)

Using Pthreads: Synchronization with pthread_join() Explained

The post discusses the advantages of using threads over separate processes, specifically in data sharing and communication. It highlights a scenario where a song title in a word processor can easily be accessed by a music player when both run as threads within the same process. The introduction of the pthread library is significant for managing threads in C. It demonstrates the use of pthread_create() to create threads and emphasizes the importance of pthread_join() to ensure proper synchronization, thereby preventing premature termination of threads. The post concludes by mentioning upcoming discussions on synchronization challenges like race conditions.

Difference between re-entrancy and thread-safety

Thread-safety of a function refers to the fact whether a function can be safely called from multiple threads simultaneously. Safety here means that even if multiple threads are executing the function simultaneously the data integrity is intact and is not intermingled. 

What is memory leak in a C program?

Memory leak is a phenomenon where a running C/C++ program or a running process or thread dynamically allocates memory block from the heap but fails to free the memory block when it no more requires the memory. This happens due to programmatic error where the handle to the allocated memory block gets lost. Over a time if the same programmatic entity (a process, or a thread or a function) comes into action repeatedly and leaks memory, all the free memory of the systems goes away and eventually the systems throws the dreaded "Out Of Memory" and crumbles down.

How to detect memory leak in c program using valgrind?

valgrind is a popular tool which can detect memory in run-time. This blog post discusses how to install, and run valgrind at linux command line to detect memory leak in a sample C program.

C++ notes: virtual function

This blog post discusses the polymorphism with the help of C++ language. The mechanism to implement polymorphism in C++ is known as Virtual Functions. With the help of a simple example I will try to explain the concept as clearly as I can.

Auto, static and global variable in C/C++ programming

  Auto variable An auto variable is a variable which is declared within the scope of a function. We call it local variable as well.…

Continue reading → Auto, static and global variable in C/C++ programming