Can someone explain the following code snippet for me?
// Bind base object so we can compute offsets
// currently only implemented for indexes.
template<class DataObj> void BindAsBase(DataObj &rowbuf)
{
// Attempting to assign working_type first guarantees exception safety.
working_type = DTL_TYPEID_NAME (rowbuf);
working_ad...
What are all operations supported by function pointer differs from raw pointer?
Is > , < , <= , >=operators supported by raw pointers if so what is the use?
...
Hello,
I would like to compare two objects through their addresses. I tried operator overloading and it does not seem to work for pointers, but works for objects themselves. The following is the relevant code:
class C {
public:
int x;
};
.
.
.
bool operator <( C *ptr_c1, C *ptr_c2 )
{
return ( (*ptr_c1).x...
I'm writing a DLL in Delphi using the below C++ example:
USERDLL_API double process_message (const char* pmessage, const void* param)
{
if (pmessage==NULL) { return 0; }
if (param==NULL) { return 0; }
if (strcmp(pmessage,"state")==0)
{
current_state *state = (current_state*) param;
return process_state( (cu...
I have two implemented classes:
class DCCmd :
public DCMessage
class DCReply :
public DCMessage
Both are protocol messages that are sent and received both ways.
Now in the protocol implementation I'd need to make a message queue, but with DCMessage being abstract it won't let me do something like this:
class DCMsgQueue{
pri...
COM interfaces methods can return various HRESULT values to signal invalid argument values passed. When do I return E_POINTER and when E_INVALIDARG?
As I understand if a method receives an index in an encapsulated collection and it is out of bounds that is E_INVALIDARG. If a method receives an Interface** pointer where it is meant to st...
I wrote a function along the lines of this:
void myFunc(myStruct *&out) {
out = new myStruct;
out->field1 = 1;
out->field2 = 2;
}
Now in a calling function, I might write something like this:
myStruct *data;
myFunc(data);
which will fill all the fields in data. If I omit the '&' in the declaration, this will not work. (...
What are the realistic outcomes of programmer bugs pertaining to pointers?
What 'bad effects' happen when programmers create pointer bugs?
Practical examples with code are preferable.
...
I have a class that implements an interface, which is made available for plugins.
The declaration of class is quite simple. There is only one instance of this class for an entire application. When the function that returns the interface is called, it calls _AddRef on the retrieved interface before passing it back as result. Unfortunately...
I am using Luabind to expose a base class from C++ to Lua from which I can derive classes in Lua. This part works correctly and I am able to call C++ methods from my derived class in Lua.
Now what I want to do is obtain a pointer to the Lua-based instance in my C++ program.
C++ -> Binding
class Enemy {
private:
std::string name;
pu...
Hi all,
I have just started to practice c++ and I am stuck at one point.
I have a Node class and the class has a constructor like this:
class Node
{
public:
Node(std::string,Node *,int,int,int,int);
private:
std::string state;
Node* parent_node;
int total_cost;
int path_cost;
...
I'm programming in C here, for Windows and various Unix platforms. I have a set of structs that have common fields, but also fields that are different. For example:
typedef struct {
char street[10];
char city[10];
char lat[10];
char long[10];
} ADDR_A;
typedef struct {
char street[10];
char city[10];
char z...
So I want a pointer to a pointer.
I've got a class that is updated in one object. In another object I want a reference to the current version of the object in the original Class. Here is sort of a simplified version of what I have going on.
Public Class Foo
'conaints information
End Class
Public Class myMainApp
Dim myHelper ...
Hello,
I am going over C and have a question regarding const usage with pointers. I understand the following code:
const char *someArray
This is defining a pointer that points to types of char and the const modifier means that the values stored in someArray cannot be changed. However, what does the following mean ?
char * const arr...
I was recently asked in an interview about the parameter for a copy constructor.
[Edited]
As a designer of C++ language implementing copy constructor feature, why would you choose constant reference parameter over a const pointer to a const object.
I had a few ideas like since a pointer can be assigned to NULL which probably doesn't m...
How to understand following complicated declarations?
char (*(*f())[])();
char (*(*X[3])())[5];
void (*f)(int,void (*)());
char far *far *ptr;
typedef void (*pfun)(int,float);
int **(*f)(int**,int**(*)(int **,int **));
EDIT : After people have cursed me, I am tagging this as homework question. :-)
...
I am doing lots of matrix arithmetic and would like to take advantage of C99's restrict pointer qualifier.
I'd like to setup my matrices as pointers to pointers to allow for easy subscripting, like so:
int **A = malloc (ncols * sizeof(int *));
A[0] = malloc (nrows * ncols * sizof(int));
for (int i=1; i < ncols; i++) {
A[i] = A[0] +...
Me and some peers are working on a game (Rigs ofRods) and are trying to integrate OpenCL for physics calculation. At the same time we are trying to do some much needed cleanup of our data structures. I guess I should say we are trying to cleanup our data structures and be mindful of OpenCL requirements.
One of the problems with using op...
I've been reading for an hour now and still don't get what is going on with my application.
Since I am using instances of object with new and delete, I need to manage the memory myself. My application needs to have long uptimes and therefore properly managing the memory consumption is very crucial for me.
Here's the static function I us...
Much to my shame, I haven't had the chance to use smart pointers in actual development (the supervisior deems it too 'complex' and a waste of time). However, I planned to use them for my own stuff...
I have situations regarding de-initing a module after they are done, or when new data is loaded in. As I am using pointers, I find my code...