private

How to Access a Private Variable?

删除回忆录丶 提交于 2019-12-10 12:03:36
问题 This question isn't meant to sound as blatantly insulting as it probably is right now. This is a homework assignment, and the spec sheet is scarce and poorly designed to say the least. We have a function: double refuel( int liter, GasStation *gs ) { // TODO: Access private variable MaxFuel of gs and decrement. } Sound simple enough? It should be, but the class GasStation comes with no function that accesses the private variable MaxFuel. So how can I access it anyway using the function refuel?

Cordova plugin from private GitHub repository

故事扮演 提交于 2019-12-10 10:53:17
问题 What is the preferred way to install a Cordova plugin from a private GitHub repository? I have purchased a private plugin from a provider who granted my git account access to their private git repository. Normally I install plugins from the cordova cli with: cordova plugin add https://github.com/somePrivateRepo/purchasedPlugin.git But this yielded the following error: Error: Failed to fetch plugin https://github.com/somePrivateRepo/purchasedPlugin.git via git. Either there is a connection

Java Reflection private method with parameters best approach?

二次信任 提交于 2019-12-10 10:49:14
问题 i am trying to call a private method using java reflection i developed a small method to call the others methods iterating over all methods and comparing by name and by parameters type i have invoke 4 methods with success. i have one question. 1). is this the best way to do it?. because i understand class.getMethod only match public methods. Java have something built-in? here is my code. public class Compute { private Method getMethod(Class clazz,String methodName,Class...parametersClass) {

private public protected access specifiers in python

时光毁灭记忆、已成空白 提交于 2019-12-10 10:11:46
问题 Can we simulate private and protected access specifiers in python? Name Mangling eg: __var=10 can simulate private but its viable to be accessed outside easily via the object. object._className__var So is there a way we could simulate or does python a solution directly which I am not aware of? 回答1: Python does not have mandatory access control like some other languages you may be used to. The philosophy of the language is "We are all consenting adults". By convention, private attributes are

How do I mark a control as 'Private' in WPF?

陌路散爱 提交于 2019-12-10 09:05:35
问题 With WinForms programs I've become accustomed to marking the Modifiers property of a control as 'Private' to prevent external classes and whatever else have you from being able to see and mess with them. Being still very green with WPF, I see no obvious equivalent in WPF that allows me to make it so external classes cannot see a control I drop onto a form or another user control or what not. I did notice something of x:FieldModifier = "Private" but I get the error "x:FieldModifier = "Private"

Can a derived class be made uncopyable by declaring copy constructor/operator private in base class?

僤鯓⒐⒋嵵緔 提交于 2019-12-10 04:10:28
问题 I thought in theory the answer to this question was yes. However, in practice, my compiler (VS2010) does not seem to complain in the following situation: I have an abstract base class providing some common interface (yet having no data members) and various sub and subsubclasses derived from it. class Base { public: Base() {} virtual ~Base() {} virtual void interfaceFunction1() = 0; virtual void interfaceFunction2() = 0; private: Base(const Base&); // all derived classes should be uncopyable

C++中将构造函数和析构函数定义为private的用意

梦想的初衷 提交于 2019-12-09 20:37:43
很多情况下要求当前的程序中只有一个object。例如一个程序只有一个和数据库的连接,只有一个鼠标的object。通常我们都将构造函数的声明置于public区段,假如我们将 其放入private区段中会发生什么样的后果?这意味着什么? 当我们在程序中声明一个对象时,编译器为调用构造函数(如果有的话),而这个调用将通常是外部的,也就是说它不属于class对象本身的调用,假如构造函数是私有的, 由于在class外部不允许访问私有成员,所以这将导致编译出错。 然而,对于class本身,可以利用它的static公有成员,因为它们独立于class对象之外,不必产生对象也可以使用它们。 此时因为构造函数被class私有化,所以我们要创建出对象,就必须能够访问到class的私有域;这一点只有class的成员可以做得到;但在我们建构出其对象之前,怎么能利用它 的成员呢?static公有成员,它是独立于class对象而存在的,“我们”可以访问得到。假如在某个static函数中创建了该class的对象,并以引用或者指针的形式将其返回(这里不 以对象返回,主要是构造函数是私有的,外部不能创建临时对象),就获得了这个对象的使用权。 下面是例子: class OnlyHeapClass { public: static OnlyHeapClass* GetInstance() { //

Marking instance variables @private

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-09 19:35:01
问题 I've noticed that a lot of Apple's interfaces use @private before their instance variable declarations. Is there a good design reason for this, and is it something I should do? 回答1: Private instance variables are used to separate interface from implementation. In Objective-C, since the class declaration must show all of the instance variables, there needs to be a way to prevent subclasses from accessing the ones that are part of the internal implementation. Otherwise, other programmers could

Using the YouTube API v3 to list all private videos

孤者浪人 提交于 2019-12-09 19:26:01
问题 Currently I'm building a site that will use a small number of user uploaded videos. These videos are uploaded to the server, then moved on to YouTube via the API v3. The private tag is set, and all videos are uploaded into one central account. My problem is; how can I access and list all these private videos via the API to display on my site? I'm not sure if this is possible. Any feed back would be much appreciated. After looking into it more I found this. After looking through the docs I

Java tool for testing private methods?

放肆的年华 提交于 2019-12-09 16:40:59
问题 There are different opinions on the meaningfulness of testing of private methods, e.g., here and here. I personally think it makes sense, the question is how to do it properly. In C++ you can use a #define hack or make the test class friend , in C# there's the InternalsVisibleToAttribute, but in Java we either have to use reflection or to make them "visible for testing" and annotate them as such in order to make the intent clear. The disadvantages of both should be quite clear. I think there