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;

Recommended Answers

All 2 Replies

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.