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.


POINTERS in C++
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.


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?


Pointers
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.


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.


Understanding Pointers
A quick guide to C pointers for people having trouble with the concepts involved.


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


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


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


Pointers and References in C++
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.


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.


Smart Pointers - Part 1
Programming tutorial for understanding "Smart Pointers".


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++.


Using Templates in C++
Learn how class and function templates can be used to increase readability and reduce code typing.This tutorial shows you how to reuse code, save typing time, prevent time spent on debugging and saving source-code space


C++ Function Templates
C++ Function templates are those functions which can handle different data types without separate code for each of them. For a similar operation on several kinds of data types, a programmer need not write different versions by overloading a function. It is enough if he writes a C++ template based function. This will take care of all the data types.