Object-InsideOut - Re: C++ Equiv of Protected?

Posted on Wed Jan 25 04:15:48 2006 by jdhedden in response to 1699 (See the whole thread of 2)
Re: C++ Equiv of Protected?
One class cannot (and shouldn't be forced to) share the lexical field arrays/hashes with derived classes. You have to use the accessors.

The equivalent of 'protected' on C++ member variables is to use 'restricted' accessor methods:
package Top; { use Object::InsideOut; my @info :Field('Std' => 'info', 'Restricted' => 1); my %init_args :InitArgs = ( 'INFO' => { 'Field' => \@info, }, ); } package Top::Middle; { use Object::InsideOut 'Top'; sub print_info { my $self = shift; print($self->get_info(), "n"); } } package main; my $obj = Top::Middle->new('INFO' => 'Some info'); # print($obj->get_info, "\n"); # Can't call restricted accessor $obj->print_info();
Write a response