Bad<Ptr> question

In a book I am learning from the author does this:

1
2
unsigned char* storage;
storage=0;


however whenever I try this I get a Bad<Ptr>
CXX0030: Error: expression cannot be evaluated
for storage when I run debug. Am I overlooking something or should this be an error?

here is an exerpt from the code in the book
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//Stash.h 
struct Stash {
  int size;      // Size of each space
  int quantity;  // Number of storage spaces
  int next;      // Next empty space
   // Dynamically allocated array of bytes:
  unsigned char* storage;
  // Functions!
  void initialize(int size);
  void cleanup();
  int add(const void* element);
  void* fetch(int index);
  int count();
  void inflate(int increase);
}; 

// Stash.cpp
void Stash::initialize(int sz) {
  size = sz;
  quantity = 0;
  storage = 0; // here is where I get the Bad <Ptr>
  next = 0;
}
That should not be giving an error...I don't see any problems with that code (aside from not using an initializer list).
Not sure if I'm right or not, but shouldn't you have to set storage = " "? I don't know if 0 translates to NULL or not.

Otherwise you could try using ZeroMemory() to clear the pointer of whatever garbage is in there when its allocated.
I don't know if 0 translates to NULL or not.


In C++, 0 and NULL are the same.

Maybe the problem is you are dereferencing the pointer? You can't do that if it is NULL.
Topic archived. No new replies allowed.