public

returning reference to private vs public member

走远了吗. 提交于 2020-01-01 18:18:47
问题 I would like to know what could be reasons to provide a public access method returning a reference instead of making the member public. QPoint has methods int& rx and int& ry that let me directly manipulate the coordinates. I guess the implentation looks similar to this: public: int& rx(){return x;} private: int x; The only idea I had so far is the following: By keeping the member private and "only" providing a reference, the class can still change to use a different data type for its

jQuery plugin creation and public facing methods

邮差的信 提交于 2020-01-01 12:09:23
问题 I have created a plugin to convert an HTML select box into a custom drop down using DIV's. All works well, but i'd like to make it a little better. see my jsFiddle At the end of the plugin I have 2 methods, slideDownOptions & slideUpOptions, I would like to make these available outside of the plugin so other events can trigger the action. Im getting a little confused how to do this and more specifically how to call the methods from both within the plugin AND from outside of the plugin. Any

Kotlin internal classes in Java visible publicly

帅比萌擦擦* 提交于 2020-01-01 11:57:29
问题 I am developing an Android crypto library in Kotlin. I have a couple of internal classes which become publicly visible in a Java app. Found this in documentations. internal declarations become public in Java. Members of internal classes go through name mangling, to make it harder to accidentally use them from Java and to allow overloading for members with the same signature that don't see each other according to Kotlin rules; Is there a way to get around this? 回答1: I have seen all of your

Kotlin internal classes in Java visible publicly

孤者浪人 提交于 2020-01-01 11:57:06
问题 I am developing an Android crypto library in Kotlin. I have a couple of internal classes which become publicly visible in a Java app. Found this in documentations. internal declarations become public in Java. Members of internal classes go through name mangling, to make it harder to accidentally use them from Java and to allow overloading for members with the same signature that don't see each other according to Kotlin rules; Is there a way to get around this? 回答1: I have seen all of your

Java - Method accessibility inside package-private class?

自古美人都是妖i 提交于 2019-12-30 08:12:53
问题 If I have a java class which is package-private (declared with "class", not "public class"), there is really no difference if the methods inside are declared public or protected or package-private, right? So which should I use, or when should I use which? I'm a bit confused. 回答1: If I have a java class which is package-private (declared with "class", not "public class"), there is really no difference if the methods inside are declared public or protected or package-private, right? Well maybe

Any performance reason to put attributes protected/private?

大憨熊 提交于 2019-12-30 07:10:50
问题 I "learned" C++ at school, but there are several things I don't know, like where or what a compiler can optimize, seems I already know that inline and const can boost a little... If performance is an important thing (gaming programming for example), does putting class attributes not public ( private or protected ) allow the compiler to make more optimized code ? Because all my previous teacher were saying was it's more "secure" or "prevent not wanted or authorized class access/behavior", but

Accessing “Public” methods from “Private” methods in javascript class

白昼怎懂夜的黑 提交于 2019-12-30 03:05:12
问题 Is there a way to call "public" javascript functions from "private" ones within a class? Check out the class below: function Class() { this.publicMethod = function() { alert("hello"); } privateMethod = function() { publicMethod(); } this.test = function() { privateMethod(); } } Here is the code I run: var class = new Class(); class.test(); Firebug gives this error: publicMethod is not defined: [Break on this error] publicMethod(); Is there some other way to call publicMethod() within

C++ why use public, private or protected inheritance?

有些话、适合烂在心里 提交于 2019-12-30 01:10:27
问题 Well there is enough information about this subject. For example this thread was very clear to me: Difference between private, public, and protected inheritance Except one point; Why is it useful? 回答1: Use public inheritance to reflect an is-a relationship . This is the main use for inheritance, especially in combination with virtual functions. It allows re-use of interface, not just of old code by new code, but also re-use of new code by old code! (because of virtual function dispatch at

C++ why use public, private or protected inheritance?

冷暖自知 提交于 2019-12-30 01:10:26
问题 Well there is enough information about this subject. For example this thread was very clear to me: Difference between private, public, and protected inheritance Except one point; Why is it useful? 回答1: Use public inheritance to reflect an is-a relationship . This is the main use for inheritance, especially in combination with virtual functions. It allows re-use of interface, not just of old code by new code, but also re-use of new code by old code! (because of virtual function dispatch at

Why make class members private?

倾然丶 夕夏残阳落幕 提交于 2019-12-29 06:30:14
问题 I've learn C++ for some time, however there is always this question which puzzles me (for years). In school, our lecturers like to declare class variables as private. In order to access it, we have to declare an accessor to access it. Sometimes we even have to make the different classes become "friends" into order to access its elements. My question is: Why make it so troublesome? What is the true rationale behind all the private and protected stuff when we can just make our life as a