Click here to Skip to main content
15,919,931 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: C/C++ Question Pin
RichardS17-Sep-05 16:47
RichardS17-Sep-05 16:47 
QuestionQuestion About Pointers in C++ Pin
17-Sep-05 5:54
suss17-Sep-05 5:54 
AnswerRe: Question About Pointers in C++ Pin
TheGreatAndPowerfulOz17-Sep-05 15:03
TheGreatAndPowerfulOz17-Sep-05 15:03 
GeneralRe: Question About Pointers in C++ Pin
BlitzPackage17-Sep-05 15:35
BlitzPackage17-Sep-05 15:35 
GeneralRe: Question About Pointers in C++ Pin
Achim Klein17-Sep-05 15:42
Achim Klein17-Sep-05 15:42 
GeneralRe: Question About Pointers in C++ Pin
BlitzPackage17-Sep-05 15:46
BlitzPackage17-Sep-05 15:46 
GeneralRe: Question About Pointers in C++ Pin
Achim Klein17-Sep-05 15:56
Achim Klein17-Sep-05 15:56 
GeneralRe: Question About Pointers in C++ Pin
RichardS17-Sep-05 17:31
RichardS17-Sep-05 17:31 
Hi,

You can't create a reference data structure in the same way you would with a pointer data structure. With pointers the compiler does not need to know what the object methods/vars are inorder to point to it. Hence the NULL pointer. As soon as you dereference the pointer you will be accessing the object, just pointing to it is no problem.

However with a reference, you are already "dereferencing a pointer" at compile time as it were. A reference stores the memory address of the object so there needs already to be a memory address for the object. Hence data structures that need to have a copy of themselves can't be just re-written easily. In the example about you would never be able to create a Node object because you would always need a Node to begin with, that Node would need another Node before it, and so on. A vicious circle.

The way around all this is to create some sort of container for the nodes.
class NodeCont
{
public:
 NodeCont (void) : m_fIsNull (true) { } // Start with a NULL node
 void Set (void) { m_fIsNull = false; } // Non-Null node now
 bool IsNull () { return fIsNull; }
protected:
 bool m_fIsNull;
};


Your actual data node could be inheritered from this class. Then your Node class would be easy to update:
class Node
{
public:
   Node (NodeCont& left, NodeCont &right) : l (left), r (right) { }

   NodeCont& l;
   NodeCont& r;
};


For NULL nodes you would just need to check the IsNull function. The trick now is to create presistant memory (memory not on the stack) for all the containers. e.g.:
NodeCont *left = new NodeCont;
NodeCont *right = new NodeCont;
Node N (*left, *right);


And that is how you can get around pointers if you really want to.

regards,
Rich



"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
GeneralRe: Question About Pointers in C++ Pin
Achim Klein18-Sep-05 1:41
Achim Klein18-Sep-05 1:41 
AnswerRe: Question About Pointers in C++ Pin
Achim Klein17-Sep-05 15:33
Achim Klein17-Sep-05 15:33 
GeneralRe: Question About Pointers in C++ Pin
BlitzPackage17-Sep-05 15:39
BlitzPackage17-Sep-05 15:39 
GeneralRe: Question About Pointers in C++ Pin
Johann Gerell17-Sep-05 19:24
Johann Gerell17-Sep-05 19:24 
GeneralRe: Question About Pointers in C++ Pin
Achim Klein18-Sep-05 1:50
Achim Klein18-Sep-05 1:50 
AnswerRe: Question About Pointers in C++ Pin
Johann Gerell17-Sep-05 19:48
Johann Gerell17-Sep-05 19:48 
QuestionAfxGetThread returning NULL in Debug Mode and causing crash Pin
Anonymous16-Sep-05 17:46
Anonymous16-Sep-05 17:46 
QuestionPure virtual function calls in Constructor Pin
RichardS16-Sep-05 11:05
RichardS16-Sep-05 11:05 
AnswerRe: Pure virtual function calls in Constructor Pin
S. Senthil Kumar16-Sep-05 20:16
S. Senthil Kumar16-Sep-05 20:16 
GeneralRe: Pure virtual function calls in Constructor Pin
RichardS17-Sep-05 16:33
RichardS17-Sep-05 16:33 
AnswerRe: Pure virtual function calls in Constructor Pin
Nemanja Trifunovic17-Sep-05 4:35
Nemanja Trifunovic17-Sep-05 4:35 
GeneralRe: Pure virtual function calls in Constructor Pin
RichardS17-Sep-05 16:31
RichardS17-Sep-05 16:31 
QuestionConvert ASCII to HEX Pin
RedDragon2k16-Sep-05 9:23
RedDragon2k16-Sep-05 9:23 
AnswerRe: Convert ASCII to HEX Pin
RichardS17-Sep-05 16:57
RichardS17-Sep-05 16:57 
GeneralRe: Convert ASCII to HEX Pin
Johann Gerell17-Sep-05 23:13
Johann Gerell17-Sep-05 23:13 
GeneralRe: Convert ASCII to HEX Pin
RichardS18-Sep-05 5:22
RichardS18-Sep-05 5:22 
GeneralRe: Convert ASCII to HEX Pin
Johann Gerell18-Sep-05 6:22
Johann Gerell18-Sep-05 6:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.