Use of void pointers (void*) and templates

In C, the use of void pointers can be extremely useful. It can be used as a universally generic pointer that can point to any type. The limitation to this is that you must know the type that the void pointer was casted from in order to obtain data from it (which usually isn't that bad). Here's example using a simple list struct.

Sponsored Links:

Related Topics

Fundamental data types
void - type with an empty set of values. It is an incomplete type that cannot be completed (consequently, objects of type void are disallowed). There are no arrays of void, nor references to void. However, pointers to void and functions returning type void (procedures in other languages) are permitted.

We are going to discuss pointers in this tutorial. Pointers are considered one of the trickiest concepts in the C++ programming. But don’t worry; we are going to explain it in a very lucid manner. I can assure that after completing this tutorial, you will be teaching pointers to your fellows around.

Smart Pointers : What, Why, Which?
Smart pointers are objects that look and feel like pointers, but are smarter. What does this mean? To look and feel like pointers, smart pointers need to have the same interface that pointers do: they need to support pointer operations like dereferencing (operator *) and indirection (operator ->). An object that looks and feels like something else is called a proxy object, or just proxy. The proxy pattern and its many uses are described in the books Design Patterns and Pattern Oriented Software Architecture.

Introducing pointers
Pointers represent an important aspect of C++. Although, newbies often get confused with pointers, even those who know other programming languages.

Distinguish between pointers and references
Pointers and references look different enough (pointers use the * and -> operators, references use .), but they seem to do similar things. Both pointers and references let you refer to other objects indirectly. How, then, do you decide when to use one and not the other?

Using pointers to access memory locations.Pointers are an extremely powerful programming tool. They can make some things much easier, help improve your program's efficiency, and even allow you to handle unlimited amounts of data.

Understanding Pointers
This article is intended to all programming enthusiasts on all levels who do wish to understand pointers in C++ language. All code presented here is not a compiler specific and all examples will be written in plain ANSI C++. Debate about pointers can stretch for miles, and you would need to go really far to master it all. If you really want to run that far, this article gives you a clear understanding of fundamental concepts about pointers and prepares you for that journey. However, those who are new to C++ programming make sure that you are able to write and run your own C++ “hello world” program, and also it is recommended that you have a basic understanding of C++ functions and classes.

Pointers to C++ Member Functions
Pointers to Member Functions are one of C++'s more rarely used features, and are often not well understood even by experienced developers. This is understandable, as their syntax is necessarily rather clumsy and obscure.
While they do not have wide applicability, sometimes member function pointers are useful to solve certain problems, and when they do apply they are often the perfect choice, both for improved performance and to make the code sensible.

Lesson 18: Pointers and Stacks in C
Today's lesson goes more into details about pointers and their usage as function's arguments. Additional tutorial about stacks in C and C++ is provided. Be sure to read this lesson carefully in order to understand it, since pointers are most important part of C programming language.

Arrays and Pointers
Learn: Relating a Pointer to an Array, A Pointer as Argument, Passing Pointers as Arguments, Passing Reference Pointers to Functions, Pointers and Multi-Dimensional Arrays, Dynamic Arrays
Dynamic Multi-Dimensional Arrays, Pointers and Arrays With Functions, Single Dimensional Arrays and Functions and more.

Pointers in C++
This code showing basic operations on pointers, such as referencing, dereferencing, etc.

Pointers in C
This Lesson is about Pointers and their useful implementation in Your future C programs. Lets start

Creating a collection class in C++
How to use a template to create a custom collection class and using the C++ std::vector STL library as well as the operator. I will expect you to understand how pointers, classes, templates and the operator works

When to use References vs. Pointers
The ability to manipulate memory and memory locations directly is part of what makes C and C++ so powerful, so dangerous, and so difficult for beginners. C only has "pointers", but C++ uses pointers and "references" that have a nicer syntax and attempt to be safer. This article will attempt to demystify these concepts in the minds of beginning C/C++ programmers.

An overview on smart pointers
Smart pointers are only useful when used with new, or the corresponding make functions (make_shared and make_unique in C++14 f.e.). So, a smart pointer is only needed, when you use new or other means of dynamic memory allocation.

Pointer Arithmetic; Adding, Subtracting and Comparing Pointers
Pointers can be added and subtracted, which sounds useless but is actually sometimes very useful. We can use pointer arithmetic to accomplish some rather deft manipulations of data that wouldn’t otherwise be possible.

How to Create a Template in C++
In C++, templates enable you to generalize a class or function so that it does not use a particular data type. You can use templates in C++ to create a function or class that can handle all kinds of data types. Learn how to create templates in this tutorial.

Templates Tutorial
Function templates are special functions that can operate with generic types. This allows us to create a function template whose functionality can be adapted to more than one type or class without repeating the entire code for each type.

Basics of function templates
This tutorial covers the basics of using function templates in C++. It shows you how to create them and explains how they work.

Using ADO in C++
How nice it is to do database programming with ADO and C++. But this combination never made the mainstream of programming.
Programming with ADO in C++ is just as easy as with Visual Basic, you just have to explicitly release COM objects, handle exceptions and work with those nasty C++ pointers. But all in all, if you can handle the added complexity of C++, then you should be able to create much more robust applications then with junior languages like Visual Basic. The best way to use ADO in C++ is to use the smart pointers created with the #import directive in Visual C++.