|
The . operator is for non-dynamic variables. The -> operator is used for pointer variables.
I think you know what a pointer is, don´t you?
"Have no fear, the saint is here!"
|
|
|
|
|
well the . and the -> actually do the same thing they server the same purpose but the difference is that the '.' (dot operator) is used when are dealing with a NORMAL object while the -> operator is used for a POINTER object like check this little snippet below
class foo
{
public :
int i;
};
when making an object of this class
foo myobject;
myobject.i = 0; //this is the normal way to access the i variable
now look at this object
foo *pobject; //now this is a pointer to object
pobject->i = 1; //this is way i will be accessed
|
|
|
|
|
ok
small words? you got em
// a header file
class A
{
public:
A();
~A();
void foo();
};
// a source file
int main(int, char**)
{
A a_object;
A* a_[ointer_to_the_object = new A();
a_object.foo();
a_pointer_to_the_object->foo();
return 0;
}
you see? when you deal with a pointer - you use -> operator......
debug - is my life style
|
|
|
|
|
Roger Wright wrote:
see code that uses the . operator to reference member functions as often as I see the -> operator used for what appears to me to be the same purpose. What the heck is the difference?
To the best of MY understanding
The member selection operator -> is used whenever the expression before is coupled with an indirection operator *
CMyObject myObj;
myObj.Test();
CMyObject* myObj;
myObj->Test();
You can acheive the same thing using
CMyObject myObj;
(*myObj).Test();
Basically when you use -> or *. are accessing members indirectly with a pointer.
The word of the day is legs, let's go back to my house and spread the word
|
|
|
|
|
Thank you for the only marginally comprehensible answer of the lot. Frankly, pointers drive me over the edge, and make me long for the resurgence of Pascal, the only language that's made any sense in the past 20 years or so. Indirection was handy in the ASM days, and I loved using it. But it seems an absurd layer of obscurity when applied to modern languages. I really hate that part of C++.
"Another day done - All targets met; all systems fully operational; all customers satisfied; all staff keen and well motivated; all pigs fed and ready to fly" - Jennie A.
|
|
|
|
|
Well, perhaps I'll add my knowledge to the heap.
Consider the following: you have an object of some type. Let's name this type 'Roger', and let it have an attribute called 'Age' (No sarcasm intended !)
Now, if in your code, you created a static object, you would use Roger MyRoger declaration. This would create a static object for you. You would then access the member variable by using MyRoger.Age = 30 , for example.
Let's take a step beyond and consider a pointer. See in front of yourself a 3D-space. In this space, you see the MyRoger -object standing at some point. Then, you create a pointer of type Roger using a declaration Roger* pToMyRoger = &MyRoger . Now, the pToMyRoger pointer points towards the MyRoger object, just like an extended finger.
A static object is aware of two things: what it is, and where it resides. A pointer to any object is aware of two things as well: where it resides, and what is to be found in that location.
For a more in-depth scenario, consider that your Roger-object (MyRoger) reserves a place for itself in memory (&MyRoger). If you issued MyRoger.Age , the compiler would get the address of MyRoger , move forwards from there to the Age variable, and retrieve it's contents. If you used a pointer, then the compiler would take the address you give to that pointer, and ASSUME that the object found from that address is the one specified by the type of the pointer (Roger*). It would then search for the Age variable again, and retrieve it.
Then to the term 'dereferencing'. When you have pointer to the object Roger (pToMyRoger), you can dereference it to an OBJECT of type Roger by using the asterisk (*) operator. For example, this declaration (*pToMyRoger).Age is the same thing as MyRoger.Age . As you might guess, *pToMyRoger equals to MyRoger hence leading us to the following conclusion: the dereferencing operator (*) can sometimes be named as the 'contents-of' operator. Thus, the contents of pToMyRoger (*pToMyRoger) equals to the object MyRoger (MyRoger). Does this make sense ?
In the conclusion, the '.' and the '->' operators behave similarly, but they are used in different contexts. For example, the following declarations do all the same things
MyRoger.Age = (*pToMyRoger).Age = pToMyRoger->Age = (&MyRoger)->Age
I am not sure about the final declaration, as I have never tested it. But, it should work according to the C++ language syntax, to which we will not dive right now
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Thanks! That helps clarify things quite a bit.
"Another day done - All targets met; all systems fully operational; all customers satisfied; all staff keen and well motivated; all pigs fed and ready to fly" - Jennie A.
|
|
|
|
|
I just finished writting a bunch of verbage and an error occurd when I sent it
And I don't think it sent...sux when that happens
Anyways...you've helped me more often then not during my times here at CP so any time I can help back i'm more then happy.
Cheers
The word of the day is legs, let's go back to my house and spread the word
|
|
|
|
|
The feelings you are having towards c++ are normal and understandable for a person trying to learn the language. Once you fully grasp the concepts and advantages (as well as disadvantages) of pointers you will view them in a much different light for sure.
|
|
|
|
|
I suppose so, though I haven't yet found any use for a pointer, nor any need to use one other than to comply with the declaration of some class or other.
"Another day done - All targets met; all systems fully operational; all customers satisfied; all staff keen and well motivated; all pigs fed and ready to fly" - Jennie A.
|
|
|
|
|
Roger Wright wrote:
But it seems an absurd layer of obscurity when applied to modern languages. I really hate that part of C++.
Technically, pointers existed long before C++.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
Not knowing the difference between . and -> does not make you a stupid guy
and Knowing the difference between . and -> does not make us any smarter either
you are OK
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
|
|
|
|
|
Hi,
Is anyone knowing if there is being code to do filter rules like the Outlook Express? Is a nicely way to building informations, and I would liking to do this.
Thanking you with flipping toes
|
|
|
|
|
hi everybody!
i was asking this question in "general" forum, but got no replays...
----
i've got an opportunity to upgrade my system to amd 64 3200+. it's preaty cheap and it would be stupid to miss it, but... i do developing under windows and linux and MOST clients of mine are the users of 32-bit architecture. in the specs of the cpu i found misterious phrase "supports both simulteniously 32 and 64 arc's" huh? so, my dilema is - miss or not miss good chance for the upgrade. What are the issues will i face after upgrade to 64 (with regard to developing under win .NET studio)? What are the consiquences for my end-users? I mean only windows users, if they have win2k (just for example!) and 32-bit cpu (pIII), and they try to run a binary that was built on my winXPpro 64-bit cpu, will they have problems?
please, share your opinion and experience, i really need it!
thanx
alex
debug - is my life style
|
|
|
|
|
It's been a while since I read my A+ book so forgive me if i'm wrong.
I believe 32 and 64 bit arc's are usually determined by the following factors:
1) Register size
2) Number of bits computer can transer per MOV instruction...your bus bandwidth I guess
Anyways, most computers now are 32 bit because the internal registers are all 32 bit with I believe the exception of a few floating point registers which are 48 or 128 or something...
So you shouldn't have any backwards incompatiability issues when developing on a 64 bit arc becuz so long as your compiler compiles using common 32 bit instruction set it should run on your 64 bit machine or my 32 bit one. Kind of like how I could use 16 bit MOV instruction on my computer, but I could only move 16 bits at a time, whereas I could also use a 32 bit MOV instruction, but now be able to move 32 bits.
.NET uses an intermediate language...I can't remember what it's called... IL maybe...?
Anyways...the .NET interpreter would determine which actual instruction to send the processor (I believe thats the idea behind .NET) so you shouldn't get any exception becuz of a bad instruction when you compile apps using .NET.
Cheers
The word of the day is legs, let's go back to my house and spread the word
|
|
|
|
|
right, thanx
the scenario you've gave requires .NET being installed on the user's computer. or not?
debug - is my life style
|
|
|
|
|
If you write an app in .NET and give it to somebody on a Windows 98 machine, I believe they would have to download the .NET framework in order to run you apps on their machine. I remember having to download the win32 SDK on win 3.1 back in the day inorder to run some neat program, I don't image this situation is much different.
Cheers
The word of the day is legs, let's go back to my house and spread the word
|
|
|
|
|
Hallo,
does anyone know where I can get a model of the MFC in ArgoUML? Or does anyone have such a model, he would send to me?
Thanks,
StHubi
"Have no fear, the saint is here!"
|
|
|
|
|
hi,
apart from using PostMessage(), i want to any method or example like callback function, or similar to delegate in C#. so that, worker thread able to communicate with user interface on a event.
i want to learn more on this. any help?
thanks!
jim.
|
|
|
|
|
Hi,
Have u tried PostThreadMessage() API , using this API u can post ur event message to ur worket thread.
for e.g
void yourFunction()
{
BOOL success = PostThreadMessage(
idThread, your thread ID
Msg, // message
wParam, // first message parameter
lParam // second message parameter
);
}
and in your Thread...
DWORD WINAPI yourThreadProc(void *ptr)
{
MESSAGE msg;
while(GetMessage(&msg,NULL, 0,0)
{
switch(msg.message)
{
---do your work accordingly ---
}
}
}
Abhishek Srivastava
Software Engineer (VC++)
India ,Noida
Mobile no 9891492921
|
|
|
|
|
hi all..
ok, this is my problem...
i have a number of namespaces in my app... now, i can call namespace 'b' from namespace 'c', but for some reason, namespace 'b' says that namespace 'a' doesn't exist...
now, i have altered the 'resovle #using...' bit correctly all the class libraries are managed class libraries and they are all VC++.NET libs...
any thoughts guys???
cheers and thanks in advance...
nik
Nik Vogiatzis
PhD Candidate: University of South Australia
+++++++++++++++++++++++++++
Developing new generation Traffic Micro-simulation Tools for Traffic Engineers
em: nikolaos.vogiatzis@unisa.edu.au
|
|
|
|
|
Hi all,
I'd posted this question earlier, but the contents have been deleted!! Anyway, my question is:
I've MDI application with FullServer option selected in step3 of AppWizard and CFormView as base class. In the code I used CreateNewDocument(), CreateNewFrame(), InitailUpdateFrame().The document is getting created, but when I try to save the document, it shows illegal operation.The code works well for CScrollView and CFormView with 'None' option for step3 of appwizard. Can anyone help me solve this?
regards
kevcs2.
|
|
|
|
|
Hi All,
can someone tell me how to close all the messageboxes and dialogboxes belonging to a particular window in an MDI client application.I cannot use CWnd::MessageBox with the corresponding window as parent for displaying a message since any other modal dialog displayed when a messagebox is active will lose it modal property.Hence I'm using AfxMessageBox.I there any other alternative solution for this.
Thanks in advance
Raghu
|
|
|
|
|
I want to make an MFC application that traverses through a series of several (up to 6) dialogs, and then returns to the main dialog.
The user starts at the main dialog box, and makes a selection, closing that dialog and opening a dialog corresponding to the selection. This process would be repeated several times. These dialogs must be able to share data and work together as a single program.
I have tried using modal dialogs but am not able to do anything once the second dialog is opened.
Does anyone have a suggestion?
Thanks,
kvan07
|
|
|
|
|
One solution is a global data structure that stores the univeral information.
Kuphryn
|
|
|
|