Sign in to follow this  
Marcus L

Question regarding 'private' keyword

Recommended Posts

Hi there,
 

I stumbled upon an issue with using the 'private' keyword in my application. It seems AngelScript doesn't mind when I access private members from derived classes, however accessing private functions from derived classes yields an error of type: "ERR : Illegal call to private method". I see that this is mentioned in the manual and is expected behavior.

However my question is why the engine won't allow private methods to get called, as it would be more consistent, and in tune with C++/Java's 'protected' keyword. As it stands it acts like a mix of 'private' and 'protected', and can cause confusion.

The real reason I'm in need of this myself is because want to have private 'init' functions (for my serializer), which also act polymorphically. As it stands this turned out to be difficult without modifying the engine (although I did manage to hack together a solution which has yet to crash).

My solution for those interested:
I changed:
if( descr->isPrivate && descr->GetObjectType() != outFunc->GetObjectType() )
to
if( descr->isPrivate && descr->GetObjectType() != outFunc->GetObjectType() && !outFunc->GetObjectType()->DerivesFrom(descr->GetObjectType()) )
in as_compiler.cpp: void asCCompiler::PerformFunctionCall

Whats your thought on the matter?
 

Thanks in advance!

EDIT: Pressing tab apparenty posted my unfinished post rolleyes.gif

Edited by Bitsauce

Share this post


Link to post
Share on other sites

There has been a previous post about private/protected confusions before too.

 

I definitely need to take a closer look at this. I agree that it has to be consistent behaviour, and I will also try to at least have an option to allow the same level of control as with C++/Java (where protected and private have different meaning).

Share this post


Link to post
Share on other sites

Yes, in my opinion that would be a great addition to an already excellent scripting engine! And having it as an option allows for those who don't need it to disable the feature (or vise-versa) smile.png
(and yes, I saw that thread and immediately felt a little guilty for opening a new one, sorry!)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this