|
|
u can consider Reference as const pointer
never say die
|
|
|
|
|
Where are you guys coming up with this stuff? If a reference was a constant pointer then you would need to use the ‘->’ operator instead of the ‘.’ Operator, or you would need to dereference it with the ‘*’ operator.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
John R. Shaw wrote: If a reference was a constant pointer then you would need to use the ‘->’ operator instead of the ‘.’ Operator, or you would need to dereference it with the ‘*’ operator.
...and it would be not possible to alter the object referenced...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
True! But what would also be true is that you could set the reference equal to anouther object if you wanted. Which C++ will not allow you to do whether it is a constant reference or not.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
I have been programming for a long time and have never tried doing what you are showing. Does the compiler actually let you set a reference to a base class object to a derived class object. I would understand if you where setting a pointer to a base class object to the address of a derived class object, but regardless of what you have heard a pointer and a reference are not exactly the same thing (although they are related).
You can set a pointer to a base class the address of an object derive from that same class. That is part of the power of C++; if you have a base class for shapes you want to draw and the base class has a virtual function for drawing shapes, then you can build an array of pointers to base class objects and then call the draw function for each of those objects. It is the derived class that does the actual drawing via the virtual function.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
I know a base pointer can be used to call derived class function (the object which points to). As you I haven't tried it yet...It came as the part of design suggestion. I just wondered and tried with the sample.
SaRath.
"Don't Do Different things... Do Things Differently..."
Understanding State Pattern in C++
|
|
|
|
|
But you said you had not tried it! Did it actually work? It would not surprize me if it did; I have just never thought it would. A reference is basically a dereference pointer; that is the compiler dereferences it for you.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Just to make things clear:
There are 3 classes A,B and C
B and C are derived from A : A has a virtual fn Display() and an int variable is declared in each class i,j and k respectively.
** And yes each class has a constructor where i assign a value to the variable's i,j,k respectively.
When we use pointers we can call :
B b;
C c;
A* a=&c;
a->display();
a=&b;
a->display();
But when we use references :
B b;
C c;
A& a=c;
a.display();
a=b;
a.display();
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
-- modified at 7:09 Wednesday 14th June, 2006
|
|
|
|
|
Its known that a reference can't be re initalized. But i just wanted to know what is happening when compiling the code A& a=c;
SaRath.
"Don't Do Different things... Do Things Differently..."
Understanding State Pattern in C++
|
|
|
|
|
wrote: Its known that a reference can't be re initalized. But i just wanted to know what is happening when compiling the code A& a=c;
A reference holds the address of an object, but behaves syntactically like an object
Now come to point what happening in A& a=c; code
'a' holds the address of the 'c' and no need of dereferencing of 'a'
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
|
Can anybody tell me how to reduce the size OpenSSL LIB ie ssleay32.lib and libeay.lib.
Thanx in advance.
never say die
-- modified at 6:25 Wednesday 14th June, 2006
|
|
|
|
|
Do you have the source code ? You can remove stuff you don't need, optimise the build for size ( not speed ), etc.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Can i do the foll conversion...
char * str1="abc";
CString str2=;
str2=str1;
-- modified at 6:24 Wednesday 14th June, 2006
|
|
|
|
|
ofcourse if u haven't defined
_UNICODE
nave
|
|
|
|
|
did xactly as mentioned in d query..n checked str2(D CString Variable)..it was empty!!!
and wat exactly is meant by the _UNICODE suggestion??
|
|
|
|
|
this will work. The cstring have the = operator overloaded for LPCSTR
char * str1="abc";
CString str2 = str1;
and about _UNICODE. now when i checked the CString have = operator overloaded for LPCWSTR.
so it will work even if _UNICODE is defined.
nave
|
|
|
|
|
CString str2;
str2=str2+';'+ str1;
never say die
-- modified at 6:33 Wednesday 14th June, 2006
|
|
|
|
|
er..wat about str2?
and d 'str' u mentioned is CString/char*??
|
|
|
|
|
Yha it was my mistake.I have replaced str by str2
never say die
|
|
|
|
|
sunit5 wrote: str2=str2+';'+ str1;
isn't this the same to the more readable :
str2 += ';' + str1;
-- TTD --
|
|
|
|
|
strcpy(str2,str1.GetBuffer(str1.GetLength()));
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
|
|
|
|
|
strcpy doesnt work with CString!!tried dat!
|
|
|
|
|
use _tcscpy_s(VS 2005) or _tcscpy
never say die
|
|
|
|