private-members

How do you make infrastructure code only visible in namespace?

a 夏天 提交于 2019-12-10 19:57:59
问题 I have an implementation of the Shunting-Yard algorithm that I am trying to integrate clearly into our framework. Currently I have it all packed into a class with a simple public interface. namespace MathematicalParser { public class ExpressionParser { public ExpressionParser(string expression, List<string> variables); public double GetNumericValue(Dictionary<string,double> variableValues); } } Inside this class there are a lot of helper classes, helper enums, static variables etc to map

Javascript: should I be hiding my implementations?

情到浓时终转凉″ 提交于 2019-12-10 14:48:19
问题 As a C# programmer, I have a bit of a habit of making things private that can and should be private, and I always get a weird feeling when a JS type exposes all its private parts to me (and that feeling is not 'aroused'). Say I have a type that has a draw method, which internally calls drawBackground and drawForeground , which make no sense to be called on their own. How should I implement this? Option 1 Foo = function(){ this.draw(); }; Foo.prototype.draw = function(){ this.drawBackground();

c++ compiler error cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'

坚强是说给别人听的谎言 提交于 2019-12-10 11:36:26
问题 Hey Im getting an error I think has to do with copying ofstream variable from reading other posts and Ive tried to change std::ofstream outfil; to std::ofstream & outfil; but I get error reference value "outfil" requires an initializer the code is: #include <algorithm> #include <fstream> #include <iostream> #include <iterator> #include <sstream> #include <string> #include <vector> #include <cstdlib> std::vector<double> GetValues_n(const std::vector<std::string>& src, int start, int end) { std

How to access private members of other template class instances? [duplicate]

时光怂恿深爱的人放手 提交于 2019-12-10 06:16:53
问题 This question already has an answer here : How to share protected members between C++ template classes? (1 answer) Closed 5 years ago . This extremely minimal example will fail to compile because A<int> cannot access the private member i in A<double> template <class T> class A { int i; public: template <class U> void copy_i_from( const A<U> & a ){ i = a.i; } }; int main(void) { A<int> ai; A<double> ad; ai.copy_i_from(ad); return 0; } I cannot find the correct way to make those template

When to use one or two underscore in Python [duplicate]

六眼飞鱼酱① 提交于 2019-12-10 03:15:08
问题 This question already has answers here : What is the meaning of a single and a double underscore before an object name? (15 answers) Closed 10 months ago . Ok I think I have understood the use of one and two heading underscores in Python. Correct me if I am wrong, In the case of one underscore, the underscore prevents the from X import * statement to import this kind of variables. In the case of two underscores, the variable's name is prepended with the name of the class it belongs to allow a

C# Private members visibility

你说的曾经没有我的故事 提交于 2019-12-09 05:17:02
问题 We have a Student class in our business model. something struck me as strange, if we are manipulating one student from another student, the students private members are visible... this strikes me as a little indecent :) class Program { static void Main(string[] args) { Student s1 = new Student(); Student s2 = new Student(); s1.ExamineStudentsMembers(s2); } } public class Student { private String _studentsPrivateMember; public Student() { _studentsPrivateMember = DateTime.Now.Ticks.ToString();

Why can a templatized derived class access its base private members on gcc?

时光总嘲笑我的痴心妄想 提交于 2019-12-08 16:25:07
问题 I'm in the process of learning c++. Now i understand that a derived class cannot access its base class private members, but why a templatized one can ? for instance something like this works fine: class base { static int x; }; template<typename T> class derived: public base{ T t; public: void setx(int i) {x=i;} int getx(){return x;} }; I'm using gcc 5.4 on linux. 回答1: This is a known bug of GCC, which seems to fail in performing access checking correctly in templates. See Bug 58740.

C++ passing reference to class' private variable - compiler issue?

狂风中的少年 提交于 2019-12-08 05:53:56
问题 Is the passing by reference of a private variable in a class to be directly changed outside that class acceptable practice? Or is this something that the compiler 'should' pick up and prevent? Example: //------------------------------------------- class Others { public: Others() {}; void ChangeIt(string &str) { str = "Changed by Others"; } }; //------------------------------------------- class Locals { private: string PrivateString; public: Locals() { PrivateString = "Set by Locals"; }; void

Modify private readonly member variable?

大兔子大兔子 提交于 2019-12-08 01:20:45
问题 I have the following code : public class MyClass { private readonly string name; public string Name { get { return name; } } public MyClass(string name) { this.name = name; } } class Program { static void Main(string[] args) { MyClass mc = new MyClass("SomeName"); } } Is there any way I can change the value of mc.name without modifying the class? 回答1: You can only use reflection typeof(MyClass) .GetField("name",BindingFlags.Instance|BindingFlags.NonPublic) .SetValue(myclassInstance, 123); 回答2

Are you explicitly unit testing a private method when you use your knowledge of the private method to choose test cases

天大地大妈咪最大 提交于 2019-12-07 14:26:17
问题 It seems as though the general consensus of the testing community is to not test private methods. Instead, you should test private methods by testing the public methods that invoke them. However, something just doesn't feel right to me. Let's take this method for example: /** * Returns the base name of the output generator class. If the class is named * Reno_OutputGenerator_HTML, this would return "HTML". * * @return string */ protected function getName() { $class = get_class($this); $matches