Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
Search the Tips
Tip Bank > C++ > Pointer Arithmetic

Pointer Arithmetic

1-20 of 79     Previous     Next
Using the Standard Library Algorithms with Arrays
by Kevin Spiteri
Pointers may be used as iterators when using the standard library algorithms found in <algorithm>.
Modifying Member Variables Inside const Member Functions
by Amit Gupta
Declaring a member variable as mutable is not the only way to mark it as modifiable within a constant member function.
Arrays of Functions
by David Bandel
Creating arrays of function pointers lets you pass functions as arguments at runtime even when you don't know the exact function needed at design time.
Arrays as Pointers in C++
by Sachin Kainth
Because the elements of an array are stored in consecutive memory addresses on the computer and the name of the array is equivalent to the address of the first element in it, it's easy to use pointers instead of subscripts to read and write the values of an array.
Deleting Elements of a Container of Pointers
by Danny Kalev
This is a common source of misunderstanding: a programmer creates a container of pointers, then fills that container with pointers to dynamically allocated objects. When the container is ...
Arrays of Pointers to Members
by Danny Kalev
You can create an array of pointers to member just as you would create arrays of any other type. The following example creates an array of pointers to member functions of class Parrot and ...
Avoiding Crashes Due to Multiple Deletes
by Nitin Kumar
Many times, a program crashes due to multiple deletes on the same pointer. In some cases, this is due to a programming error that can be removed. There are situations, however, where it may be ...
Casting To and From void*
by Danny Kalev
In C++, pointers are strongly-typed. Therefore, you can't assign a void pointer to any other pointer type without casting it ...
Null Pointers and Delete
by Danny Kalev
C++ guarantees that operator delete checks its argument for null-ness. If the argument is 0, the delete expression has no effect. In other words, deleting a null pointer is a safe (yet useless) ...
Streams and Pointers
by Danny Kalev
Look at the following program. It compiles correctly under every standard-conforming compiler. At first, this may seem surprising because seemingly, because it's impossible delete an object which is ...
Taking an Address of a Member Function
by Danny Kalev
The name of an ordinary function is implicitly converted to its memory address. For ...
References
by DevX Pro
I want to know if the following declaration is possible: int *p; p= new int; int &refval= *p;
Taking the Address of a Member Function
by DevX Pro
class a; typedef void(a::*func)(); class a { protected: int x; public: func f; void fg(){f=&a::as;}; void as(); }; This code compiles in Visual C++6.0. However, Borland C 3.1 gives me the following error at line "void fg(){f=as;};": "member function must be called or its address must be taken". I don't understand why.
Constructors and Member Variables
by DevX Pro
After I have already declared an object, how can I call its constructor again to re-initialize its member variables?
Taking an Address of a Pointer
by Danny Kalev
The sequence && is parsed as the logical AND operator. According to the Maximal Munch parsing principle, it's never construed as two & (address of) ...
Invoking a Function Through a Pointer
by Danny Kalev
When you call a function through a pointer to function, use that pointer as if it were the function itself, not a pointer. For ...
Problem with Pointer-to-Member in Templates
by DevX Pro
I am trying to write a template that somewhat resembles how an inner class works in Java: template class Callback { public: Callback(T& t) : parent(t) { } void Execute() { parent.*F(); } private: T& parent; }; In Visual C++ 6, this complains that F is an invalid template argument, but when I remove the T and hardcode a class in as: class Parent; template class Callback { /* ... */ }; ... it works fine. Is this just a problem with VC6 or am I doing something wrong or ambiguous?
Casting Pointers To Members
by Danny Kalev
C++ allows casting a pointer to member functions of one type to another pointer to member, as long as the signatures of the two match. However, the results of such a cast are implementation-defined. ...
Enumerator with Zero Value and Null Pointer Constants
by Danny Kalev
Here's a topic that was recently discussed at the Standardization committee. Suppose we have the following enum ...
Checking If a Function Pointer is Valid
by DevX Pro
I am collecting a number of function pointers in C++ and before I call them I want to check to see if they have been set. I really want to avoid calling them if they aren't valid. I have tried the following "if func != Null { ... " but I get an error.
1-20 of 79     Previous     Next
Sitemap