Object-InsideOut - C++ Equiv of Protected?

Posted on Wed Jan 25 01:26:04 2006 by je44ery
C++ Equiv of Protected?
I like how in C++ child classes inherit parent attributes/fields/members.
class CPolygon { protected: int width, height; public: void set_values (int a, int b) { width=a; height=b;} }; class CRectangle: public CPolygon { public: int area () { return (width * height); } };
In this case, the CRectangle just starts using width & height without declaring it. How possible will this be to do in OIO? I've tried this:
$ cat test_me.pl #!/usr/bin/perl -w use strict; use warnings; use Top::Middle; my $obj = Top::Middle->new( 'info' => 'some_data_or_whatever' ); $obj->method(); exit 0; $ cat Top.pm use strict; use warnings; package Top; use Object::InsideOut; my @info :Field('Standard' => 'info'); my %init_args :InitArgs = ( 'INFO' => { 'Field' => \@info, }, ); 1; $ cat Top/Middle.pm use warnings; use strict; package Top::Middle; use Object::InsideOut 'Top'; sub method { my $self = shift; my $string = $info[$$self]; print "$string\n"; } 1;
But I get this:
# ./test_me.pl Global symbol "@info" requires explicit package name at Top/Middle.pm line 12. Compilation failed in require at ./test_me.pl line 6. BEGIN failed--compilation aborted at ./test_me.pl line 6.
If I start using Exporter, which doesn't seem right, it doesn't work either.
$ cat Top.pm use strict; use warnings; package Top; use Object::InsideOut 'Exporter'; BEGIN { our @EXPORT_OK = qw(@info); } my @info :Field('Standard' => 'info'); my %init_args :InitArgs = ( 'INFO' => { 'Field' => \@info, }, ); 1; $ cat Top/Middle.pm use warnings; use strict; package Top::Middle; use Object::InsideOut 'Top' => [ qw(@info) ]; sub method { my $self = shift; my $string = $info[$$self]; print "$string\n"; } 1;
This is the result then:
# ./test_me.pl Use of uninitialized value in concatenation (.) or string at Top/Middle.pm line 13.
Direct Responses: 1701 | Write a response