Oh the joys of being a memory management noob !
I'm getting bit by some Objective-C code, eventhough I understand the basics of pointers, I've seen these two different constructs, without being able to really understand their difference.
Can anyone enlighten me ?
Edited my question, the constructs didn't behave differently, instead ...
Why do I get a compilation error when I call a base-class function with a pointer to a pointer to an inherited class?
Example:
class cFoo {};
class cBar : public cFoo {};
void func1(cFoo *) {} // base class
void func2(cFoo **) {} // base class
void main(void)
{ cBar bar, *pbar; // inherited class
func1(&bar); // compiles ...
The VS documentation states
Half the size of a pointer. Use within a structure that contains a pointer and two small fields.
What, exactly, is this type and how is it used, if ever?
...
Hi,
I having a problem in my website where I have 2 objects held in session, both object are structured differently and do not have any links to each other (not intentionally). Both objects however, have a collection of "Travellers". What I am trying to do is modify one collection by adding or removing "Travellers", when a finish button...
(I'm not sure if that title is worded correctly, as I'm still new to C++)
I have two classes, loosely represented here:
class SuperGroup
{
public:
LayoutObj theLayout;
}
class SomeClass
{
public:
LayoutObj myLayout;
SuperGroup myGroup;
}
During SomeClass's constructor, I want to set myGroup.theLayout to be pointing to So...
In C++, what is the difference between:
void func(MyType&); // declaration
//...
MyType * ptr;
func(*ptr); // compiler doesnt give error
func(ptr); // compiler gives error i thought & represents memory address so
// this statement should correct as ptr is only a pointer
// or address of some real var.
...
Hi, I have a confusing problem in my code, in which one object gets initialized properly, but when I look at it through a parent reference, its properties arent initialized anymore.
I assigned id's for my objects, and I am perfectly sure that there are no duplicate objects lying around. When looking through the parent, the child is not i...
When we talk about dereference, is it necessary that * should be used in it? If we access the referent of the pointer in some other way, can it be considered as dereferencing a pointer or not, like:
char *ptr = "abc" ;
printf( "%c" , *ptr ); // Here pointer is dereferenced.
printf( "%s" , ptr ); // What about this one?
That is the f...
I need a value to be calculated in it's getter method if it isn't set already. I prefer to use a nullable int construction, so I don't need another bool to check if it's already been calculated.
My first hunch was to go for a NSInteger *. I can check if it's NULL and otherwise set a value to it. But I don't know if it's possible, since ...
Consider the following class structure:
class Filter
{
virtual void filter() = 0;
virtual ~Filter() { }
};
class FilterChain : public Filter
{
FilterChain(collection<Filter*> filters)
{
// copies "filters" to some internal list
// (the pointers are copied, not the filters themselves)
}
~Filter...
I am trying to implement binary search tree operations and got stuck at deletion.
11
/ \
10 14
Using inorder traversal as representation of tree initially output is 10 11 14.
Deleting node 10, output expected is 11 14 but I am getting 0 11 14.
Deleting node 14, output expected is just 11 but I am getting 0 11 67837.
Please ex...
Most of my C++ programming experience has been projects for school. In that way, our usage of external libraries (ie boost) has been either prohibited or discouraged. Therefore we could not use smart pointers unless we wanted to write our own, which was usually beyond the scope of the projects. I'm just wondering in real world projects, ...
Hi,
I have a function returning float* where it's actually filled as an array in the returning function such that
float* some_fnc()
{
float *x=malloc(sizeof(float)*4);
x[0]=......
}
...
// in main
float y[4];
y=some_fnc();
however I get an "Incompatible types" error, is it normal? Is there a way to overcome this w/o declaring...
Hello,
gcc 4.4.4
Maybe I am being dumb. But what am I doing wrong?
char x[10];
char y[] = "Hello";
while(y != NULL)
*x++ = *y++;
Many thanks for any advice,
...
assume
char a='s';
now i want to store the address of variable a in char pointer p
char *p=&a;
if i use cout << p; then i get the value s, not the address!
can anyone explain the reason why is it so?
...
I have a global variable that is a *char. My main function header reads as int main(int argc, char* argv[argc]){...}. These two lines of code have to remain the way they are. The first argument of my main function is a number of type *char, that I convert to a char using atoi(...);. I am basically changing the ASCII value to its corresp...
Hiya im trying to write a code for basic 1D Monte-Carlo integration. To do so I need a list of pseudo-random numbers which I can then input into a function (stored in another subroutine). I've given the list of random numbers a pointer but when I try to dereference it in main I get "error: incompatible types when assigning to type ‘dou...
This part of my code checks to see that when the user clicks on a contact, the contact actually has a phone number, otherwise a message is displayed and nothing else is done.
I am confused as to where my null pointer exception is coming from....
Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, nu...
I am trying to use an HIMAGELIST from an unmanaged dll which gives me the result as an IntPtr.
Is there a way for me to turn this IntPtr into a Bitmap or an Image so I can use it for Winforms buttons, as in:
myButton.Image = intPtrImage
...
Hello, I have a situation that looks like the following code:
#include <iostream>
class A
{
public:
A() { std::cout << "A created!" << std::endl; }
~A() { std::cout << "A destroyed!" << std::endl; }
virtual const char* Name() { return "A"; }
};
class B : public A
{
public:
B() { std::cout << "B created!" << std::endl;...