private-members

Should I document my private methods? [closed]

瘦欲@ 提交于 2019-12-18 13:52:43
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . Private methods documentation can only be seen by who has access to the source code. Is it worth the effort spent on it? 回答1: Personally, I feel that it is. Documentation is often the most useful to future developers maintaining your software - especially member documentation

Declaring private member variables

ぃ、小莉子 提交于 2019-12-18 04:46:15
问题 I've started learning Objective-C a few weeks ago and I still don't understand how to manage the encapsulation of a class correctly. What is the best way to declare a private member variable in a class? It seems that setting the right getter/setter for your member variable with "@property" is the right way to go, more than just declaring it "@private" in the interface. But it seems to me that this still gives other classes an access to these variables. Even if you declare the property

How to write a simple class in C++?

天大地大妈咪最大 提交于 2019-12-17 22:35:52
问题 I have been reading a lot of tutorials on C++ class but they miss something that other tutorials include. Can someone please show me how to write and use a very simple C++ class that uses visibility, methods and a simple constructor and destructor? 回答1: Well documented example taken and explained better from Constructors and Destructors in C++: #include <iostream> // for cout and cin class Cat // begin declaration of the class { public: // begin public section Cat(int initialAge); //

UINavigationController crash because of pushing and poping UIViewControllers

百般思念 提交于 2019-12-17 21:13:25
问题 The issue: I have a UINavigationController as as subview of UIWindow, a rootViewController class and a custom MyViewController class. The following steps will get a Exc_Bad_Access, 100% reproducible.: [myNaviationController pushViewController:myViewController_1stInstance animated:YES]; [myNaviationController pushViewController:myViewController_2ndInstance animated:YES]; Hit the left back tapBarItem twice (pop out two of the myViewController instances) to show the rootViewController. After a

How to create an object with private members using Object.create() instead of new

半腔热情 提交于 2019-12-17 19:43:14
问题 EDIT: I figured it out from Bergi's answer in the end. Thanks Bergi. pubPrivExample = (function () { return { init : function () { var private; this.setPrivate = function (p) { private = p; }; this.getPrivate = function () { return private; }; }, public : "This is public\n" }; }()); var a; a = Object.create(pubPrivExample); a.init(); a.setPrivate("This is private"); document.write(a.getPrivate()); EDIT: It seems the answers to my question are off at a tangent. I'm really not interested in a

Private members in Java inheritance

风流意气都作罢 提交于 2019-12-17 15:45:16
问题 I was told that for a Java subclass it can inherit all members of its superclass. So does this mean even private members? I know it can inherit protected members. Can someone explain this to me. I am now totally confused. 回答1: No, the private member are not inherited because the scope of a private member is only limited to the class in which it is defined. Only the public and protected member are inherited. From the Java Documentation, Private Members in a Superclass A subclass does not

Why are private fields private to the type, not the instance?

余生长醉 提交于 2019-12-17 03:23:06
问题 In C# (and many other languages) it's perfectly legitimate to access private fields of other instances of the same type. For example: public class Foo { private bool aBool; public void DoBar(Foo anotherFoo) { if (anotherFoo.aBool) ... } } As the C# specification (sections 3.5.1, 3.5.2) states access to private fields is on a type, not an instance. I've been discussing this with a colleague and we're trying to come up with a reason why it works like this (rather than restricting access to the

“Incomplete type” in class which has a member of the same type of the class itself

谁说我不能喝 提交于 2019-12-17 02:12:23
问题 I have a class that should have a private member of the same class, something like: class A { private: A member; } But it tells me that member is an incomplete type. Why? It doesn't tell me incomplete type if I use a pointer, but I'd rather not use a pointer. Any help is appreciated 回答1: At the time you declare your member, you are still defining the A class, so the type A is still undefined. However, when you write A* , the compiler already knows that A stands for a class name, and so the

Accessing private member variables from prototype-defined functions

╄→гoц情女王★ 提交于 2019-12-16 20:06:08
问题 Is there any way to make “private” variables (those defined in the constructor), available to prototype-defined methods? TestClass = function(){ var privateField = "hello"; this.nonProtoHello = function(){alert(privateField)}; }; TestClass.prototype.prototypeHello = function(){alert(privateField)}; This works: t.nonProtoHello() But this doesn’t: t.prototypeHello() I’m used to defining my methods inside the constructor, but am moving away from that for a couple reasons. 回答1: No, there's no way

PHP: Calling a private method from within a class dying badly

自作多情 提交于 2019-12-13 15:22:49
问题 So this might sound a little convoluted. Fingers crossed I come across clearly. I'm working in an MVC framework in PHP. I load a controller /report/index which calls to a helper <? class ReportController extends Controller { public function index() { $foo = MainReport::get_data($_REQUEST); } } ?> Inside the helper <? class MainReport extends foo { public function get_data($_REQUEST) { // do stuff return $stuff_done; } } ?> It I run it like ^this all's well and good. Unfortunately, I want to