protected

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

“Protect” text box value from input (HTML form)

烂漫一生 提交于 2019-12-01 05:31:07
I was wondering whether it is possible to assign a value to an HTML text box and protect it. What I mean is make it´s content unmodifiable, so that when the form gets submitted im "sure" it was this value which was submitted. BTW I realize the easier way would be not to "listen" fot this input and just assign it but it would come in handy to be able to do what´s stated above. I hope the question is clear enough, please ask for any needed clarification. Thanks in advance! EDIT: I was definitely not clear enough but I tried to express that i should hold the value after submitted (not modifiable

Protected member function address in derived class is not accessible

烂漫一生 提交于 2019-12-01 03:26:52
#include <iostream> class A { protected: void foo() {} }; class B : public A { public: void bar() { std::cout << (&A::foo) << std::endl; } }; int main() { B b; b.bar(); } Here I am trying to get address of protected member function of base class. I am getting this error. main.cpp: In member function ‘void B::bar()’: main.cpp:5: error: ‘void A::foo()’ is protected main.cpp:13: error: within this context make: *** [all] Error 1 Changing foo to public works. Also printing &B::foo works. Can you please explain why we can't get address of protected member function of base class? B is allowed to

Is there a use for making a protected destructor virtual?

自作多情 提交于 2019-12-01 03:21:11
/*Child is inherited from Parent*/ class Parent { public: Parent () //Constructor { cout << "\n Parent constructor called\n" << endl; } protected: ~Parent() //Dtor { cout << "\n Parent destructor called\n" << endl; } }; class Child : public Parent { public: Child () //Ctor { cout << "\nChild constructor called\n" << endl; } ~Child() //dtor { cout << "\nChild destructor called\n" << endl; } }; int main () { Parent * p2 = new Child; delete p2; return 0; } If I make Parent 's destructor virtual, then I obtain an error, so what is the purpose of making a protected destructor virtual? Just to give

Python xlwt - making a column readonly (cell protect)

徘徊边缘 提交于 2019-12-01 03:09:03
问题 Is there a way to make a particular cell read-only/write protected in python xlwt? I know there's is a cell_overwrite_ok flag which does not allow to overwrite contents of cells (all cells) but can this be done on cell by cell basis. Thanks, Sun 回答1: Excel cells have a locked attribute that is enabled by default. However, this attribute is only invoked when the worksheet's protection attribute is also set to True . If the worksheet is not protected, the locked attribute is ignored. Therefore,

Cannot access protected member of base class in derived class

人盡茶涼 提交于 2019-12-01 02:47:00
I have the following code: struct A { protected: A() {} A* a; }; struct B : A { protected: B() { b.a = &b; } A b; }; It strangely doesn't compile. The culprit is the b.a = &b; assignment: both GCC and clang complain that A() is protected, which shouldn't be a problem because B inherits A. Which dark corner of the standard have I come into? David Rodríguez - dribeas The meaning of protected is that the derived type will have access to that member of its own base and not of any random object * . In your case, you care trying to modify b 's member which is outside of your control (i.e. you can

PHP Private variable access from child

南楼画角 提交于 2019-12-01 02:46:45
问题 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

Any performance reason to put attributes protected/private?

别说谁变了你拦得住时间么 提交于 2019-11-30 23:56:00
I "learned" C++ at school, but there are several things I don't know, like where or what a compiler can optimize, seems I already know that inline and const can boost a little... If performance is an important thing (gaming programming for example), does putting class attributes not public ( private or protected ) allow the compiler to make more optimized code ? Because all my previous teacher were saying was it's more "secure" or "prevent not wanted or authorized class access/behavior", but in the end, I'm wonder if putting attributes not public can limit the scope and thus fasten things. I

When would I use package-private in Java? [duplicate]

血红的双手。 提交于 2019-11-30 20:41:35
This question already has an answer here: Pros and cons of package private classes in Java? 8 answers I love access control in any language, but I find that in Java I almost never (if ever) use the package-private access modifier (or lack thereof). I realize that inner classes can be private , protected , or package-private , but outer classes can only be package-private or public . Why can an outer class be package-private but not protected ? What is the benefit of restricting classes/methods/fields to be seen by the entire package, but not subclasses? I use package-private classes and

protected data in abstract class

别等时光非礼了梦想. 提交于 2019-11-30 11:48:40
My question involves specifically Java, abstract classes, and the use of protected data. I am being told that all the data should be private, and protected getters/setters used only. Now, I understand we want to shield data from direct manipulation by casual users of the class, and that public data members in general are a questionable practice. I have looked at "Java protected fields vs public getters" ( Java protected fields vs public getters ), but I still am dubious that: protected int i; is worse in an abstract class than: private int i; protected int geti(); protected void seti(int j); I