User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,564 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,578 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 2832 | Replies: 2
Reply
Join Date: Aug 2004
Posts: 13
Reputation: the_one2003a is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
the_one2003a the_one2003a is offline Offline
Newbie Poster

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

  #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;
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2004
Location: Hanover
Posts: 152
Reputation: cosi is an unknown quantity at this point 
Rep Power: 5
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?

  #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  
Join Date: Aug 2004
Posts: 13
Reputation: the_one2003a is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
the_one2003a the_one2003a is offline Offline
Newbie Poster

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

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 5:49 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC