Jump to content

member access levels


photo

Recommended Posts

Posted

The docs state as follows;

 

 

Member Access Levels

 

 

UnigineScript provides two different levels for accessing class members:

  • public means that a member can be accessed from the outside of the class instance
  • private means that only the class instance can accesse such member

All class members are public by default.

 

 

 

So until now I've just coped by having everything public as thats the default, but when there are no public or private keywords in UnigineScript, how do I achieve a private access level as described here?

Posted

Unigine script has public and private keywords. The scoping works in the C++ way:

class Foo {
int public_i;
void public_foo() { }
 private:
int private_i;
void private_foo() { }
 public:
int public_j;
void public_bar() { }
};

Posted

Oh I see now, I was not using the correct syntax, as I was not using the access modifier in a code block with a colon, e.g. "private int someInt;" would not work. I didn't see an example of this in the docs so perhaps it would be an idea to include it?

Posted

But its not working :)

 

class base
 	{
 	private:
		void private_f() {log.message("hello from private member!\n");}
 	public:
		void public_f() {log.message("hello from public member!\n");}
 	};
  class test : base
 	{
 	void foo()
		{
		base::private_f();
		base::public_f();
		}
 	};
 test bar = new test();
 bar.foo();

 

I see both messages in my log. Its no C++ behavior.

Posted

In Unigine script private memebers are also seen inside inherited classes too.

  • 3 weeks later...
×
×
  • Create New...