Click here to Skip to main content
16,007,885 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: HttpSendRequest Pin
Paul M Watt17-Jan-03 20:39
mentorPaul M Watt17-Jan-03 20:39 
GeneralRe: HttpSendRequest Pin
geo_m18-Jan-03 2:15
geo_m18-Jan-03 2:15 
GeneralPassing structs by pointer rather than reference Pin
Dean Goodman17-Jan-03 11:39
Dean Goodman17-Jan-03 11:39 
GeneralRe: Passing structs by pointer rather than reference Pin
Maximilien17-Jan-03 11:46
Maximilien17-Jan-03 11:46 
GeneralRe: Passing structs by pointer rather than reference Pin
Jörgen Sigvardsson17-Jan-03 12:10
Jörgen Sigvardsson17-Jan-03 12:10 
GeneralRe: Passing structs by pointer rather than reference Pin
Maximilien17-Jan-03 12:59
Maximilien17-Jan-03 12:59 
GeneralRe: Passing structs by pointer rather than reference Pin
Jörgen Sigvardsson17-Jan-03 14:34
Jörgen Sigvardsson17-Jan-03 14:34 
GeneralRe: Passing structs by pointer rather than reference Pin
Jörgen Sigvardsson17-Jan-03 15:05
Jörgen Sigvardsson17-Jan-03 15:05 
Or what about this one?
class SomeClass {
     RefClass& ref;
public:
     SomeClass(RefClass& ref_) : ref(ref_) { ... }
};
 
.... somewhere in 10<sup>6</sup> lines of code ....
RefClass* pRef = new RefClass();
SomeClass* pObj = new SomeClass(*pRef);

.... somewhere else among those 10<sup>6</sup> lines of code ....
delete pRef;


See what I mean? SomeClass::ref isn't valid. Yes it's a bug, but you can't say that ref is valid after the delete pRef. Same thing goes for pointers to object. Just because a pointer is not NULL doesn't make it valid. That's a dangling pointer, and as you can see, there are also dangling references. In both cases you have a bug on your hands, but it still doesn't make your previous statement true, which was my main argument all along. Smile | :)


BTW, you can do this in VS.NET and most likely VC6:
struct Test { int x; };
 
int _tmain(int argc, _TCHAR* argv[])
{
    Test& ref = *((Test*)NULL);
    return 0;
}


No crash, no nothing. Yet, ref will reference "an object" at NULL. Put a breakpoint on return 0 and you'll see. Smile | :)

I still believe that the only advantage of references over pointers are purely syntactical.

--
There's a new game we like to play you see. A game with added reality. You treat me like a dog, get me down on my knees.

We call it master and servant.

GeneralRe: Passing structs by pointer rather than reference Pin
Tim Smith17-Jan-03 12:59
Tim Smith17-Jan-03 12:59 
GeneralRe: Passing structs by pointer rather than reference Pin
Jörgen Sigvardsson17-Jan-03 14:46
Jörgen Sigvardsson17-Jan-03 14:46 
GeneralRe: Passing structs by pointer rather than reference Pin
Gary R. Wheeler18-Jan-03 14:18
Gary R. Wheeler18-Jan-03 14:18 
GeneralRe: Passing structs by pointer rather than reference Pin
Jörgen Sigvardsson18-Jan-03 14:39
Jörgen Sigvardsson18-Jan-03 14:39 
GeneralRe: Passing structs by pointer rather than reference Pin
Tim Smith17-Jan-03 13:02
Tim Smith17-Jan-03 13:02 
GeneralRe: Passing structs by pointer rather than reference Pin
Dean Goodman17-Jan-03 13:11
Dean Goodman17-Jan-03 13:11 
GeneralCreating and Using a DLL in Dev-C++ Pin
Aidman17-Jan-03 11:29
Aidman17-Jan-03 11:29 
GeneralFile open and loop Pin
Doug3317-Jan-03 11:22
Doug3317-Jan-03 11:22 
GeneralRe: File open and loop Pin
Dean Goodman17-Jan-03 12:43
Dean Goodman17-Jan-03 12:43 
GeneralRe: File open and loop Pin
Mike Nordell17-Jan-03 23:31
Mike Nordell17-Jan-03 23:31 
GeneralMemory leak Pin
Shay Harel17-Jan-03 10:17
Shay Harel17-Jan-03 10:17 
GeneralRe: Memory leak Pin
AlexO17-Jan-03 10:31
AlexO17-Jan-03 10:31 
GeneralRe: Memory leak Pin
Shay Harel17-Jan-03 10:40
Shay Harel17-Jan-03 10:40 
GeneralRe: Memory leak Pin
AlexO17-Jan-03 11:08
AlexO17-Jan-03 11:08 
GeneralRe: Memory leak Pin
Shay Harel17-Jan-03 15:26
Shay Harel17-Jan-03 15:26 
GeneralCString Casting! Pin
Alex H 198317-Jan-03 10:06
Alex H 198317-Jan-03 10:06 
GeneralRe: CString Casting! Pin
Shay Harel17-Jan-03 10:12
Shay Harel17-Jan-03 10:12 

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.