Re: static + pointer and reaching the private field of another class
From: Victor Bazarov (v.Abazarov_at_comAcast.net)
Date: Wed, 16 Feb 2005 00:04:31 -0500
"mehmet canayaz" <email@example.com> wrote...
> I have a class called [...]
We much better understand C++ here. Why don't you simply post your
code instead of explainging what it is?
> But I saw an implementation of the same static function that was able
> to see the private field "name" using pointers such as :
> foo x = new foo ( my_array[i]->name)
> so as he incremented my_array he was creating new foo objects and
> copying them in another array, and this was working..
> I do not understand how this works because bar.cpp and foo.cpp has
> nothing in common except bar.cpp includes foo.h . is this is enough for
> bar to be able to see the private field of foo objects? -I dont think
> so -
> Does it have anything to do with static ? or pointers?
Probably. I don't see any static or pointers in your post, though.
Try again, and this time post C++.
> ps: when we changed the second implementation as
> foo x = new foo (*my_ar[i].name )
> it didn't work.
Probably because . has higher precedence than *. Try
foo x = new foo( (*my_ar[i]).name );