private

On a nonconst object, why won't C++ call the const version of a method with public-const and private-nonconst overloads?

我只是一个虾纸丫 提交于 2019-12-01 13:42:54
问题 class C { public: void foo() const {} private: void foo() {} }; int main() { C c; c.foo(); } MSVC 2013 doesn't like this: > error C2248: 'C::foo' : cannot access private member declared in class 'C' If I cast to a const reference, it works: const_cast<C const &>(c).foo(); Why can't I call the const method on the non const object? 回答1: From the standard: 13.3.3 If a best viable function exists and is unique, overload resolution succeeds and produces it as the result. Otherwise overload

case class private constructor - need for readResolve implementation

北慕城南 提交于 2019-12-01 12:53:12
问题 I was just googling to find out how to create a case class with private constructor. Below is the correct way for doing this as described in How to override apply in a case class companion object A { def apply(s: String, i: Int): A = new A(s.toUpperCase, i) {} //abstract class implementation intentionally empty } abstract case class A private[A] (s: String, i: Int) { private def readResolve(): Object = //to ensure validation and possible singleton-ness, must override readResolve to use

GitHub Clone Error: Cannot clone with EOF error

北战南征 提交于 2019-12-01 12:05:55
I am trying to clone my project from GitHub private repo using Ubuntu 13.04. I am getting error as below all the time error: RPC failed; result=18, HTTP code = 200| 17 KiB/s fatal: The remote end hung up unexpectedly fatal: early EOF fatal: recursion detected in die handler I have tried the following command as well but not difference git config --global http.postBuffer 524288000 Is there anything i may be missing? Btw, I am able to clone without problem in windows. VonC First check if the issue persists, because there were some issues this morning with GitHub. See its status history : Today 6

ActionScript - Read Only Property and Private Set Method?

蓝咒 提交于 2019-12-01 11:37:29
one thing i've never really understood about AS3 is that you can't have a private set method and a public get method together. from within my class i would like to assign values that would call a private set function: myNumber = 22 ; but i need to pass that number as a parameter to a function myNumber(22); for example: package { //Imports import flash.display.Sprite //Class public class NumberClass extends Sprite { //Properties private var myNumberProperty:Number //Constructor public function NumberClass(myNumber:Number):void { this.myNumber = myNumber; init(); } //Initialize private function

How to test an object's private methods in Scala

一个人想着一个人 提交于 2019-12-01 09:41:58
问题 I have an example object: object Foo { private def sayFoo = "Foo!" } And I want to test the private sayFoo method without the following workarounds: 1. Without defining it as package private 2. without defining it as protected and than inheriting it in the test class I saw one possible solution which is to extend privateMethodTester but it doesn't seem to work for objects just classes. Now, I know that some, if not many, say that you are not suppose to test private methods but rather only

Is it possible to compare private attributes in Ruby?

对着背影说爱祢 提交于 2019-12-01 08:39:04
I'm thinking in: class X def new() @a = 1 end def m( other ) @a == other.@a end end x = X.new() y = X.new() x.m( y ) But it doesn't works. The error message is: syntax error, unexpected tIVAR How can I compare two private attributes from the same class then? There are several methods Getter: class X attr_reader :a def m( other ) a == other.a end end instance_eval : class X def m( other ) @a == other.instance_eval { @a } end end instance_variable_get : class X def m( other ) @a == other.instance_variable_get :@a end end I don't think ruby has a concept of "friend" or "protected" access, and

Why won't Ruby allow me to specify self as a receiver inside a private method?

旧城冷巷雨未停 提交于 2019-12-01 08:28:22
Ruby as an Object Oriented Language. What that means is whatever message I send, I strictly send it on some object/instance of class. Example: class Test def test1 puts "I am in test1. A public method" self.test2 end def test2 puts "I am in test2. A public Method" end end makes sense I call method test2 on self object But I cannot do this class Test def test1 puts "I am in test1. A public method" self.test2 # Don't work test2 # works. (where is the object that I am calling this method on?) end private def test2 puts "I am in test2. A private Method" end end When test2 is public method I can

Is it possible to compare private attributes in Ruby?

 ̄綄美尐妖づ 提交于 2019-12-01 06:37:49
问题 I'm thinking in: class X def new() @a = 1 end def m( other ) @a == other.@a end end x = X.new() y = X.new() x.m( y ) But it doesn't works. The error message is: syntax error, unexpected tIVAR How can I compare two private attributes from the same class then? 回答1: There are several methods Getter: class X attr_reader :a def m( other ) a == other.a end end instance_eval : class X def m( other ) @a == other.instance_eval { @a } end end instance_variable_get : class X def m( other ) @a == other

Javascript dynamically getter/setter for private properties

╄→гoц情女王★ 提交于 2019-12-01 06:09:44
I want to create getter/setter methods dyanmically to retrieve private properties. This is what I did. First of all, I made the class: function winClass (posX, posY, w, h) { var x = posX || 0; var y = posY || 0; var width = w || 0; var height = h || 0; } Then I extended winClass with getter/setter methods, as follows: winClass.prototype.getX = function () { return x; } winClass.prototype.setX = function (val) { x = val; } And then I tested: var win1 = new winClass (10, 10, 100, 100); document.write (win1.getX ()); But the following error comes when I try to setup the 'getX' method: 'x is not

PHP Private variable access from child

蓝咒 提交于 2019-12-01 05:47:28
so I'm trying to work out an issue I'm having in designing PHP classes. I've created a base class, and assigned private variables. I have child classes extending this base class, which make reference and changes to these private variables through functions of the base class. Here's an example, keep in mind I'm still confused about the difference between private and protected methods/variables (let me know if I'm doing it wrong!): base.class.php <?php class Base { private $test; public function __construct(){ require('sub.class.php'); $sub = new Sub; echo($this->getTest()); } public function