How to access a Public Pointer value of a class directly?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2004
Posts: 13
Reputation: the_one2003a is an unknown quantity at this point 
Solved Threads: 0
the_one2003a the_one2003a is offline Offline
Newbie Poster

How to access a Public Pointer value of a class directly?

 
0
  #1
Aug 15th, 2004
Hi
I made a class that has a public integer pointer
and I use this pointer in main like code below: (Just a sample code,I know about memory leaks and other related bugs,just a sample)

#include<iostream.h>

class Cat
{
public:
int *Pointer;
};

main()
{
Cat *pCat;
pCat=new Cat;

pCat->Pointer = new int;
pCat->*Pointer=34 //this makes a compiler error

delete pCat->Pointer;
return 0;

}
I need to access this(Pointer) public pointer of class cat directly not from class methods;
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 153
Reputation: cosi is an unknown quantity at this point 
Solved Threads: 1
cosi's Avatar
cosi cosi is offline Offline
Junior Poster

Re: How to access a Public Pointer value of a class directly?

 
0
  #2
Aug 15th, 2004
pCat->Pointer says give me the member variable of the pCat instance object. pCat->Pointer is type int*. So we can do this *(pCat->Pointer) to get at the value.

Because of operator precedence rules, this also works *pCat->Pointer.

Hope this helps!


Ed
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 13
Reputation: the_one2003a is an unknown quantity at this point 
Solved Threads: 0
the_one2003a the_one2003a is offline Offline
Newbie Poster

Re: How to access a Public Pointer value of a class directly?

 
0
  #3
Aug 16th, 2004
Hi Cosi and thanks for your great help
it solved my prob.
I hope to be able to help you in this stuff

sincerely
the_one2003a
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC