|
41-60 of 79
Previous
Next |
|
Introducing Pointers to Members
by Danny Kalev
Pointers to members are one of the most intricate syntactic constructs in C++, and yet, they are a very powerful feature too. In future tips, I will discuss pointers to members in further detail and ...
|
|
Why you shouldn't store auto_ptr objects in STL containers
by Danny Kalev
Most C++ users already know that they shouldn't use auto_ptr objects as elements of STL containers. However, fewer users know exactly why this is so. ...
|
|
Array of Objects
by DevX Pro
I have two questions. How do I pass an array of objects as an argument? How do I fix an error like "do or while loops are not expanded inline"?
|
|
Accessing the Addresses of Class's Member Functions
by Danny Kalev
You can take the addresses of a class's static and non-static member functions. However, the class's constructor(s) and destructor are an exception to the rule. You cannot take their addresses nor ...
|
|
Declaring References to Functions
by Danny Kalev
You can declare a reference to a function, just like you can declare a pointer to a function. For ...
|
|
Living Without Null References
by Danny Kalev
In C, algorithms that rely on pointers such as bsearch() and lfind() return a null pointer to indicate that the sought after element wasn't found. Unlike a pointer, a reference must always be bound ...
|
|
Opaque Pointer
by DevX Pro
What exactly is an opaque pointer?
|
|
Returning a Pointer to a Member Function
by DevX Pro
Let's say I have a class foo, with a lot of functions that take no arguments and return SomeType:
SomeType foo::bar()
SomeType foo::quux()
SomeType foo::quuux()
SomeType foo::quuuux()
Now I have a pointer to this type of funct :
SomeType (foo::*pfn)();
Now comes the tough part, I want to return it:
?????? SomeFnct()
{
SomeType (foo::*pfn)();
pfn = foo::quux;
return pfn;
}
What do I write instead of the ??????
|
|
Uses of the ptrdiff_t Data Type
by Danny Kalev
C and C++ define a special type for pointer arithmetic, namely ptrdiff_t, which is a typedef of a platform-specific signed integral type. You can use a variable of type ptrdiff_t to store the result ...
|
|
Constant Pointer
by DevX Pro
Can you expalin the difference between the following statements in some examples and when do we need them:
const char *ptr; //
char *const ptr; //
|
|
Passing More Arguments to a Callback Function
by Danny Kalev
Callback functions have a fixed signature so you cannot alter the number or type of the arguments it takes. For example, the standard qsort() function takes a pointer to a function that has the ...
|
|
Never Use Incompatible Pointers to Member Functions
by Danny Kalev
A reader posted a message on one of the C++ newsgroups recently. He had to port a huge project from Borland C++ 5.0 to Visual C++ 6.0. The project uses the callback mechanism through pointers to ...
|
|
Creating a Callback Function Pointer
by DevX Pro
I am using Microsoft Visual C++ 6.0 and am trying to create a callback function pointer to the public member of a class, but I keep getting the following error:
error C2664: 'callback' : cannot convert parameter 1 from 'void' to 'void (__cdecl *)(void)'
Here is the code I am trying:
#include
class bb
{
public:
void callback(void (*f)());
void callback2();
bb();
virtual ~bb();
};
bb::bb()
{
}
bb::~bb()
{
}
void bb::callback(void (*f)())
{
f();
}
void bb::callback2()
{
cout callback(tmp->callback2());
return 0;
}
TIA for any help.
|
|
Functions Returning Arrays
by DevX Pro
Is it possible for a function to return an array instead of a single value?
|
|
Constraints on Pointer Arithmetic Past an Array's End
by Danny Kalev
In Standard C and C++, the address of the first element past the end of an array can be used in pointer arithmetic. Thus, you can initialize a vector with the contents of a built-in array, like ...
|
|
Far pointers in VC 5-6.0
by DevX Pro
I was trying to do some direct memory stuff (writing to the DOS console buffer or a graphics screen) using my Visual C++ compiler. Unfortunately, the compiler is telling me that "far is an obsolete keyword." What is the solution to get to absolute memory addresses outside of the data segment? For example:
char far * videobuffer = 0xA0000000;
|
|
Smart Pointer
by DevX Pro
Could you give me an exact definition of smart pointers, and how does a reference counting smart pointer work?
|
|
Void Pointer and -> Operator
by DevX Pro
I am a beginner to C++ and have looked into several resources but still have some questions. Can you tell me what a void pointer is and what it is used for (implementation)? Also, what is the - |