Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > pointer-to-member data and pointer-to-member functions and access specifiers

Reply
Thread Tools

pointer-to-member data and pointer-to-member functions and access specifiers

 
 
Stephen Howe
Guest
Posts: n/a
 
      11-04-2012
Hi

I having been trying to find if pointer-to-member data and pointer-to-member functions are subject to access specifiers in any way (public, private or protected) and so far have drawn a blank.

Are they subject to or not subject to access specifiers?

Thanks

Stephen Howe


 
Reply With Quote
 
 
 
 
Öö Tiib
Guest
Posts: n/a
 
      11-05-2012
On Monday, 5 November 2012 01:24:22 UTC+2, Stephen Howe wrote:
> Hi
>
> I having been trying to find if pointer-to-member data and pointer-to-member
> functions are subject to access specifiers in any way (public, private or
> protected) and so far have drawn a blank.
>
> Are they subject to or not subject to access specifiers?


I maybe do not understand what you ask. I see no difference between pointer
to member type and some other type.

These are types. You can not modify access to such types. If
class type is visible then types of pointers to its instances and
members are also visible as types.

When you declare a member variable of that type (like any type) private
then it is accessible only privately. If public member function returns a
value of that type (like any type) then it is usable publicly.


 
Reply With Quote
 
 
 
 
Stephen Howe
Guest
Posts: n/a
 
      11-06-2012
>> Are they subject to or not subject to access specifiers? The question is not too clear, but maybe you are confusing compile-time with run-time?

No, I meant compile-time. It has become clear to me.
An example

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

class B
{
public:
void bset(int val) { bval_ = val; }
private:
void bset2(int val) { bval_ = val; }
private:
int bval_;
};

int main()
{
B b;

void (B::*f1)(int) = &B::bset;
(b.*f1)(7);
void (B::*f2)(int) = &B::bset2; // LINE 19
(b.*f2)(;

return 0;
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


Line 19 above will fail to compile, because bset2 is private and main() has no special priviledges to set f2 to point to bset2.
It amounts to the fact that pointers-to-member functions when being initialised or assigned are subject to the same rules governing public/private/public access.

And if the example above had pointers-to-member data, again public/private/public access rules also apply.

Thanks

Stephen Howe
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
access specifiers for friend functions Rahul C++ 3 01-08-2008 04:23 AM
printf format specifiers %m and %n$ rh00667 C++ 2 03-02-2007 06:07 PM
access specifiers Sourav Ruby 3 09-21-2006 02:31 PM
Multiple inheritance and access specifiers issue. Tapeesh C++ 8 01-13-2006 02:30 AM
access specifiers and memory layout Steven T. Hatton C++ 10 07-10-2005 07:04 PM



Advertisments