Advertisement

Question regarding 'private' keyword

Started by August 18, 2014 06:44 PM
3 comments, last by WitchLord 9 years, 11 months ago

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

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).

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
That would be a nice addition!

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!)

I've added the support for 'protected' class members in revision 2099.

Regards,

Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement