Mike wrote:[color=blue]
> How do I get a pointer of an object?
>
> e.g.
>
> std::string s;
>
> How do I get a pointer to s so I can use s->Method();
>
>[/color]
And what, may I ask, is wrong with s.Method()?
HTH,
--ag
[Use `&', the address-of operator if a pointer is what you *really*
want. In the above case you don't.]
I will (ir)regularly write about things that are important to me -- that I hope interest you.
Of course, since I see most things as being political, that will be most of it.
"Artie Gold" <artiegold@aust in.rr.com> wrote in message
news:3umr6pF11k g7hU1@individua l.net...[color=blue]
> Mike wrote:[color=green]
>> How do I get a pointer of an object?
>>
>> e.g.
>>
>> std::string s;
>>
>> How do I get a pointer to s so I can use s->Method();[/color]
> And what, may I ask, is wrong with s.Method()?[/color]
Because I'm not really using std::string (using my own class) - I want to
access the pointer it returns from another class.
Mike wrote:[color=blue]
> "Artie Gold" <artiegold@aust in.rr.com> wrote in message
> news:3umr6pF11k g7hU1@individua l.net...
>[color=green]
>>Mike wrote:
>>[color=darkred]
>>>How do I get a pointer of an object?
>>>
>>>e.g.
>>>
>>>std::strin g s;
>>>
>>>How do I get a pointer to s so I can use s->Method();[/color]
>>
>>And what, may I ask, is wrong with s.Method()?[/color]
>
>
> Because I'm not really using std::string (using my own class) - I want to
> access the pointer it returns from another class.
>
>[/color]
Huh? `Pointer it returns from another class?'
In any event, the answer remains the same as before -- which you elided:
[Use `&', the address-of operator if a pointer is what you *really*
want. In the above case you don't.]
I will (ir)regularly write about things that are important to me -- that I hope interest you.
Of course, since I see most things as being political, that will be most of it.
Artie Gold wrote:[color=blue]
> Mike wrote:[color=green]
>> Because I'm not really using std::string (using my own class) - I
>> want to access the pointer it returns from another class.
>>
>>[/color]
>
> Huh? `Pointer it returns from another class?'
>
> In any event, the answer remains the same as before -- which you
> elided:
>
> [Use `&', the address-of operator if a pointer is what you *really*
> want. In the above case you don't.][/color]
Well, '&' would be wrong to use on a pointer returned from somewhere, though
it might be necessary for the thing that returns it.
To the OP, how to make a pointer:
MyClass ob;
MyClass *pOb = &ob;
pOb->Method;
If the pointer is returned from somewhere, then just use it:
MyClass *pOb = ob2.GetMyClassP ointer();
pOb->Method();
"Mike" <mikestanworth@ gmailNOSPAM.com > wrote in message
news:uBqhf.4114 $aU5.2403@newsf e3-win.ntli.net...[color=blue]
> How do I get a pointer of an object?
>
> e.g.
>
> std::string s;
>
> How do I get a pointer to s so I can use s->Method();[/color]
You cannot write 's->Method()' for two reasons:
's' is not a pointer, and 'std::string' has no
member function named 'Method()'.
Obtain a pointer to a std::string object the same
as for any other type of object; with the address
(&) operator.
Comment