Pointer to an object in a created class  
Author Message
Trevbang





PostPosted: Visual C++ Express Edition, Pointer to an object in a created class Top

I am trying to make a pointer to an object in a class that I created.

here is the class declaration

class Pits

{

int seeds;

public:

Pits (int);

void inputAccept (int);

int seednumber () {return seeds;}

};

Here is my object declaration in int main()

Pits reg1 (4);

I need to point to the object reg1 in another function so that I can manipulate its data. What do I do




Visual Studio Express Editions27  
 
 
Reza Nourai - MSFT





PostPosted: Visual C++ Express Edition, Pointer to an object in a created class Top

If I understand your question correctly, you are trying to write another function (call it foo), that you want to access the reg1 directly instead of a copy of it If that is the case you could have something like this:

int main()

{

Pits reg1(4);

Foo(&reg1);

// reg1.seeds now would be 9.

}

void Foo( Pits* p )

{

// perform some action on p

p->seeds += 5;

}

-Reza