Re: Passing an object pointer to function
- From: Stefan Ascher <no@xxxxxxxx>
- Date: Tue, 16 Aug 2005 21:44:20 +0200
In article <F1E47B10-0892-4320-9AB7-2B983AE088BA@xxxxxxxxxxxxx>, Robby
wrote...
> The above code works fine, however what if in main I wanted to create a
> pointer to an object on the heap using the following line:
>
> SimpleCat * pRags = new SimpleCat;
>
> and then passing only the pointer of the object to my function: Please
> consider the following code which does not complile?
[...]
// Pass a pointer to a SimpleCat object
// not a pointer to an int
void Function1(SimpleCat *pRags);
int main()
{
int a;
SimpleCat * pRags = new SimpleCat;
// pRages is already a pointer so you can omit the &
Function1(pRags);
// Use the -> operator
cout << Frisky->GetAge();
}
// Se above
void Function1(SimpleCat *pRags)
{
pRags->SetAge(50);
}
--
stefan
.
- References:
- Passing an object pointer to function
- From: Robby
- Passing an object pointer to function
- Prev by Date: Re: How to get Computer Name given IP address?
- Next by Date: Re: Passing an object pointer to function
- Previous by thread: Re: Passing an object pointer to function
- Next by thread: Re: Passing an object pointer to function
- Index(es):
Relevant Pages
|