473,326 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

What does -> mean in C++

Hello everybody,

I am a bit confused about this operator -> could anybody explain this for me. The reason I am confused is that every document I read to get an explaination about it, explain it in different way which has created confusion in my mind. So, are there many uses of this operator or is it used only for one purpose. e.g, what would the following statement mean:

app->displayAnyError(err);

or e.g the following:

basicApp()->uiManager()->addForm( this );

Any kind of help and support would be appreciated.

Riz
Nov 11 '06 #1
3 2691
horace1
1,510 Expert 1GB
Consider a structure Student
Expand|Select|Wrap|Line Numbers
  1. // define structure type to hold student information 
  2. struct Student {                       
  3.                 char name[20];        // student name 
  4.                 int age;              // student age 
  5.                };
  6.  
  7. Student student,                 // define a variable to hold student data 
  8.         *p_student = &student;   // define a pointer to the structure
  9.  
This defines type Student, variable student of type Student and p_student a 'pointer to type Student' initialised to point to student. The pointer can be used to access the members of the structure, e.g. to set up the age and name of the student:
Expand|Select|Wrap|Line Numbers
  1.      (*p_student).age = 20;
  2.      strcpy((*p_student).name, "daisy");
  3.  
Because the dot (.) operator has a higher precedence than the indirection operator (*) the parentheses are required to force the correct association using p_student as the pointer, i.e. the expression *p_student.age is using the structure member p_student.age as though it is a pointer to something. The use of pointers with structures is very common and an equivalent simpler notation using the -> structure pointer operator is generally used:
Expand|Select|Wrap|Line Numbers
  1.      p_student->age = 30;
  2.      strcpy(p_student->name, "mary");
  3.  
Nov 11 '06 #2
Thanks horace for the explaination and such a quick response,

Now I got an idea. But I noticed that when u used the dot (.) operator u used indirection operator (*) with the pointer variable p_student. While with the -> structure pointer operator you didnt use the indirection operator *. Is this a type or this is really the case?

Waiting again for ur quick responnse.

Riz
Nov 11 '06 #3
horace1
1,510 Expert 1GB
Thanks horace for the explaination and such a quick response,

Now I got an idea. But I noticed that when u used the dot (.) operator u used indirection operator (*) with the pointer variable p_student. While with the -> structure pointer operator you didnt use the indirection operator *. Is this a type or this is really the case?
Waiting again for ur quick responnse.

Riz
p_student->age is shorthand for (*p_student).age
Nov 11 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Chris Cioffi | last post by:
I started writing this list because I wanted to have definite points to base a comparison on and as the starting point of writing something myself. After looking around, I think it would be a...
65
by: perseus | last post by:
I think that everyone who told me that my question is irrelevant, in particular Mr. David White, is being absolutely ridiculous. Obviously, most of you up here behave like the owners of the C++...
7
by: Dan V. | last post by:
Situation: I have to connect with my Windows 2000 server using VS.NET 2003 and C# and connect to a remote Linux server at another company's office and query their XML file. Their file may be...
35
by: GTO | last post by:
I do not believe that C# is the future of C++. I also do not believe that adding two thousand new library functions to the standard library is the future of C++. But what is the future of C++? Is...
17
by: Paul | last post by:
HI! I get an error with this code. <SCRIPT language="JavaScript"> If (ifp==""){ ifp="default.htm"} //--></SCRIPT> Basicly I want my iframe to have a default page if the user enters in...
35
by: Sunil | last post by:
Hi all, I am using gcc compiler in linux.I compiled a small program int main() { printf("char : %d\n",sizeof(char)); printf("unsigned char : ...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
37
by: Erick-> | last post by:
hello!! I was looking at some code in C... and saw this "exotic" operator |=. first time with it, what exactky does??? thanks in advance. Erick->
15
by: robert maas, see http://tinyurl.com/uh3t | last post by:
Here's the source: #include <stdio.h> #include <errno.h> main () { char* str = "9999999999"; long long int llin; char* endptr; /* Set by strtoll */ int nch; errno = 0; llin = strtoll(str,...
32
by: Stephen Horne | last post by:
I've been using Visual C++ 2003 for some time, and recently started working on making my code compile in GCC and MinGW. I hit on lots of unexpected problems which boil down to the same template...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.