My program is crashing every time I try to store a COM pointer into a struct, and then later try to use the original pointer. I don't have debug access to tell exactly what's wrong.
pRend->cp = cpRT;
ID2D1SolidColorBrush *scBrush;
ERF(cpRT->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::CornflowerBlue), &scBrush));
It crashes on Cr...
I just realized after years of writing C++, that I can safely delete a NULL pointer. So I figure, I'm not the only one that wasn't aware of this. Now I feel silly for all my
if(p) delete p;
code laying around.
Am I the only one that hadn't realized this? Or is it a less known feature of C++?
...
'Strict aliasing' optimization needs special care from the source code, s.a. using a union instead of pointer casts. Is there a way to detect using preprocessor directives (#if/else) whether the compiler is trying to do such optimizations?
I would like to maintain the old and non-strict-aliasing-prepared code path for processors and com...
I was under the impression that they were the same thing. However, it looks to my like they are being treated differently here. The part I am confused about looks like this.
Foo* initFoo(char* name);
int main
{
Foo* foo;
char* player_name[25];
scanf("%s", player_name);
foo = initFoo(player_name);
}
Foo* initFoo(char* name)
{
...
Hi,
C++ references have two properties:
They always point to the same object.
They can not be 0.
Pointers are the opposite:
They can point to different objects.
They can be 0.
Why is there no "non-nullable, reseatable reference or pointer" in C++? I can't think of a good reason why references shouldn't be reseatable.
Edit:
The ...
Hi guys,
I have a C# program that creates a video and saves it to the disk in real-time. Instead of doing that, I want it to write it directly in a pipe connected with ffmpeg...
The function that keeps saving the video in the disk, which I can not control, receives an IntPtr with a reference to the file.
So, I need to create a pipe or...
I'm wondering if anyone can give me a good example of using pointers in C# in .Net and why you chose to use pointers?
...
I'm having some trouble with this code:
//Creating a new ImageElement Struct
ImageElement oElement = new UM0516.ImageElement();
//Create a pointer and allocate enough room for the struct type
IntPtr pElement = Marshal.AllocHGlobal(Marshal.SizeOf(new UM0516.ImageElement()));
//Copy the contents of the struct into the allocated memory spa...
I'm searching for a proper way to clean my pointers.
Here the example code:
class Parent {
protected:
int m_Var;
public:
Parent() : m_Var(0) {}
virtual ~Parent() {}
void PubFunc();
};
class Child : public Parent {
protected:
bool m_Bool;
public:
Child() : m_Bool(false) {}
virtual ~C...
After reading a question on the difference between pointers and references, I decided that I'd like to use references instead of pointers for my class fields. However it seems that this is not possible, because they cannot be declared uninitialized (right?).
In the particular scenario I'm working on right now, I don't want to use normal...
I am writing a library in C++ and have some functions that work with modules. An example would look like this:
void connect(Module *a, Module *b);
The problem is, that it would be sometimes handy if the function accepted also references (some of the Modules may be allocated on the stack and some on the heap and all the &s and *s get b...
I'm trying to store a pointer in an array.
My pointer to a pointer is class object is:
classType **ClassObject;
So i know i can allocate it by using the new operator like this:
ClassObject = new *classType[ 100 ] = {};
I'm reading a text file, with punctuation and here is what i have so far:
// included libraries
// main function...
I am very new to C# (just started learning in the past week).
I have a custom DLL written in C with the following function:
DLLIMPORT void test_function (double **test)
What I am looking to do is have a pointer from C# for the array 'test'.
So, if in the DLL function I have test[0] = 450.60, test[1] = 512.99 etc. I want to be able t...
I'm a bit confused with JavaScript's delete operator. Take the following piece of code:
var obj = {
helloText: "Hello World!"
};
var foo = obj;
delete obj;
After this piece of code has been executed, obj is null, but foo still refers to an object exactly like obj. I'm guessing this object is the same object that foo pointed to.
...
Sorry if the question isn't clear; I found it pretty hard to explain in one sentence.
Say I have a struct with a member which is a struct, e.g. the following:
struct A {
struct B b;
};
Lets say I intend instances of this structure to be heap-allocated always. Is there anything to be gained by changing it to this? (i.e. keeping a ...
I have a std::vector with n elements. Now I need to pass a pointer to a vector that has the last n-1 elements to a function.
For example, my vector<int> foo contains (5,2,6,87,251). A function takes vector<int>* and I want to pass it a pointer to (2,6,87,251).
Can I just (safely) take the iterator ++foo.begin(), convert it to a pointer...
I need to pass a pointer through a scripting language which just has a double and string type, for this I only have to worry about 32-bit pointers.
Seeing as the pointers are 32-bit, I figured doubles had enough precision to safely store the pointer, which works, however the problem arises with some pointers to stream, presumably due to...
duplicate:
Difference between pointer variable and reference variable in C++
What does Class& mean in c++ and how is it different from Class*?
Class& foo;
Class* foo;
...
What does this code mean? Is this how you declare a pointer in php?
$this->entryId = $entryId;
...
I'm writing some C++ code that manipulates a bunch of vectors that are changing in size and are thus being reallocated constantly.
I would like to get a "pointer" into these vectors that remains valid even after reallocation of the vector. More specifically, I just want these "pointers" to remember which vector they point into and the ...