private-members

Test a public method which calls a private method using NUnit

元气小坏坏 提交于 2019-12-22 08:39:03
问题 I have a public method in a class that internally calls a particular private method within that class. It looks something like this : public class MyClass : IMyClassInterface { public List<int> MyMethod(int a, int b) { MyPrivateMethod(a, b, ref varList, ref someVal); } private void MyPrivateMethod(int a, int b, ref List<int> varList, ref double someval) { } } Now, I basically want to test this public method using NUnit. I am using NMock 2.0 for mocking. How do I do it? Since, it internally

Groovy @ symbol before fields

こ雲淡風輕ζ 提交于 2019-12-20 11:10:13
问题 What does @ means before a field name in Groovy? For some classes I am able to access private fields that are not directly accessible, let's take ComposedClosure for example: public class Person { private String name } def u = new Person(name:"Ron") println u.@name //Ron println u.name //Ron a = {2} >> {3} println a.@first //first closure object println a.first //runtime error 回答1: It allows you to override groovy's use of property accessors. If you write: println u.name groovy will invoke

Typescript: private member is suddenly undefined

北战南征 提交于 2019-12-20 03:38:09
问题 So, I've got a basic Typescript application, that shouldn't actually cause any major problems, but it seems, that something's going wrong here and I have no idea what. I do have this private member minUpdateRate in my GameContainer class, that is initialized in the constructor. This seems to go well, because when GameContainer.start() is called, the console.log() method will print out 1 . However, when the GameContainer.render() method is called, it seems to be out of the scope or something,

PowerMockito throws NullPointerException when trying to stub private overloaded method

*爱你&永不变心* 提交于 2019-12-20 03:25:17
问题 I'm (still) trying to check if bar(Alpha, Baz) called bar(Xray, Baz) using PowerMockito (as bar(Xray, Baz) is private ) - without actually calling the later, given my MCVE class Foo below. (I went through the same class earlier, with all methods in Foo being public - in case you've got a déjà vu...) public class Foo { private String bar(Xray xray, Baz baz) { return "Xray"; } private String bar(Zulu zulu, Baz baz) { return "Zulu"; } public String bar(Alpha alpha, Baz baz) { if(alpha.get()

Private template classes/structs visibility

浪尽此生 提交于 2019-12-20 02:27:22
问题 I don't understand why in the following code, I am allowed to create the function print_private_template while the compiler complains about print_private_class : #include <cstdio> class A { private: template <unsigned T> struct B { }; struct C { }; public: template <unsigned T> B<T> getAb() { return B<T>(); } C getAc() { return C(); } }; template<unsigned T> void print_private_template(const A::B<T> &ab) { printf("%d\n", T); } void print_private_class(const A::C &ac) { printf("something\n");

Java setting private fields inside constructors

百般思念 提交于 2019-12-19 17:05:49
问题 Common design practice is to make instance variables private and have public getters and setters to access them. But many times I have seen code samples on the internet that have constructors that assign values directly to the private instance variable instead of using the setters inside constructors. Am I missing something? public class Person{ private String name; public Person(String name){ //is this right, seems like the whole encapsulation purpose is defeated this.name = name; //shouldn

Can't declare ifstream class member in header file

和自甴很熟 提交于 2019-12-19 10:25:40
问题 I am trying to declare an ifstream object in a header file as is shown but I get an error saying that it cannot be accessed. I have tried various things such as making it into a pointer instead, initialising in the .c file etc. but my code can't seem to get part the declaration of it. ReadFile.h: #ifndef READFILE_H #define READFILE_H #include "cv.h" #include "highgui.h" #include <iostream> #include <fstream> class ReadFile{ private: std::ifstream stream; public: std::string read(); ReadFile()

How to hide private members of a Class?

大兔子大兔子 提交于 2019-12-19 05:42:12
问题 I've been using visual studio for some time and it annoys me everytime when I work with Classes. The problem is, when I create an object of a Class I tend to see the private members belongs to that class and I don't want to, because what if I create a class with 10+ private variable, then it will be a nightmare, there must be a way to hide private members, If there is a way could you please share it with me? Thank you :) EDIT: Here is a picture that will help you understand what I'm talking

How is access for private variables implemented in C++ under the hood?

本秂侑毒 提交于 2019-12-19 05:14:58
问题 How does the compiler control protection of variables in memory? Is there a tag bit associated with private variables inside the memory? How does it work? 回答1: If you mean private members of instances, then there's no protection whatsoever at run-time. All protection takes place at compile-time and you can always get at the private members of a class if you know how they are laid out in memory. That requires knowledge of the platform and the compiler, and in some cases may even depend on

MSIL - how do you invoke a private method from MSIL?

て烟熏妆下的殇ゞ 提交于 2019-12-18 16:51:32
问题 I'm writing a "weak event factory" - code which converts any Delegate into a new delegate with an identical signature, but with implementing a WeakReference on the target. I'm using MSIL to avoid calls to Delegate.CreateDelegate (which performance have shown to be slow). The weak reference delegates work perfectly as long as the underlying method (the Method of the original delegate), was declared public. As soon as a private or anonymous method is used, the MSIL bombs at run time with a