private

Can a derived class be made uncopyable by declaring copy constructor/operator private in base class?

橙三吉。 提交于 2019-12-05 04:48:04
I thought in theory the answer to this question was yes. However, in practice, my compiler (VS2010) does not seem to complain in the following situation: I have an abstract base class providing some common interface (yet having no data members) and various sub and subsubclasses derived from it. class Base { public: Base() {} virtual ~Base() {} virtual void interfaceFunction1() = 0; virtual void interfaceFunction2() = 0; private: Base(const Base&); // all derived classes should be uncopyable Base& operator=(const Base&); // no data members }; My compiler found it unproblematic to even implement

Besides accessibility, what else access-specifiers effects?

泪湿孤枕 提交于 2019-12-05 04:29:57
Besides the normal explenation of being visible or not to derived classes, is their any other difference? If you make it more visible, is it taking more or less memory, does it slow thing down or...? Nawaz Apart from the accessibility of members outside or to the derived classes, access specifiers might affect the object layout. Quoting from my other answer : Usually, memory address for data members increases in the order they're defined in the class . But this order may be disrupted at any place where the access-specifiers ( private , protected , public ) are encountered . This has been

Truly Private Variables in Python 3

*爱你&永不变心* 提交于 2019-12-05 03:30:23
So I know the way to make a variable "private" in python like this: class Foo: def __init__(self): self.__private = 'bar' This "works" and doesn't, as shown below: foo = Foo() '__private' in vars(foo) #False '_Foo__private' in vars(foo) #True Now, I understand this is the way to make private variables in python and I like this way. It allows you to mangle names so that no subclasses accidentally override this (because it begins with the class's name), and that nobody will accidentally use it. It also gives you the power to change the private variables if you know what you are doing . Also, it

Docker - Unable to push image to private registry

天大地大妈咪最大 提交于 2019-12-05 00:16:56
I have created my own private registry on my server by pulling and running the registry image. sudo docker run -d -p 5000:5000 registry After which, I tried to tag a simple image and push it to the server. sudo docker tag ubuntu:latest localhost:5000/myprivateubuntu And I received this error: Error: Invalid registry endpoint ... Get ... If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add '--insecure-registry localhost:5000' to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag;

private template functions

六眼飞鱼酱① 提交于 2019-12-05 00:13:44
I have a class: C.h class C { private: template<int i> void Func(); // a lot of other functions }; C.cpp // a lot of other functions template<int i> void C::Func() { // the implementation } // a lot of other functions I know, that it's not the best idea to move template implementation in cpp file (because it won't be seen from other cpp's, which could include the header with the template declaration). But what about private functions? Could anyone tell me if there are cons of implementing of private template functions in a .cpp file? When a function template is used in a way that triggers its

PowerMock access private members

别说谁变了你拦得住时间么 提交于 2019-12-04 23:34:24
After reading: https://code.google.com/p/powermock/wiki/BypassEncapsulation i realized, i don't get it. See in this example: public class Bar{ private Foo foo; public void initFoo(){ foo = new Foo(); } } How can i access the private member foo by using PowerMock (For example to verify that foo is not null)? Note: What i don't want is modifying the code with extra get methods. Edit: I realized that i missed a sample code block on the linked page with the solution. Solution: Whitebox.getInternalState(bar, "foo"); That should be as simple as writing the following test class: public class BarTest

Erroneous private base class inaccessible?

拜拜、爱过 提交于 2019-12-04 23:24:26
问题 Compiling this code using g++ 4.2.1: struct S { }; template<typename T> struct ST { }; template<typename BaseType> class ref_count : private BaseType { }; template<typename RefCountType> class rep_base : public RefCountType { }; class wrap_rep : public rep_base<ref_count<S> > { typedef rep_base<ref_count<S> > base_type; // line 11 }; I get: bug.cpp:1: error: ‘struct S’ is inaccessible bug.cpp:11: error: within this context However, if I change the wrap_rep class to use ST : class wrap_rep :

C++ Is private really private?

别来无恙 提交于 2019-12-04 22:40:02
I was trying out the validity of private access specifier in C++. Here goes: Interface: // class_A.h class A { public: void printX(); private: void actualPrintX(); int x; }; Implementation: // class_A.cpp void A::printX() { actualPrintX(); } void A::actualPrintX() { std::cout << x: } I built this in to a static library (.a/.lib). We now have a class_A.h and classA.a (or classA.lib) pair. I edited class_A.h and removed the private: from it. Now in another classTester.cpp: #include "class_A.h" // the newly edited header int main() { A a; a.x = 12; // both G++ and VC++ allowed this! a.printX(); /

C++: Private virtual functions vs. pure virtual functions [duplicate]

北慕城南 提交于 2019-12-04 22:32:10
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Private virtual method in C++ If I understood correctly from this post (Private virtual method in C++), making a virtual function in a base class makes the derived classes able to override it. But it seems things stop there. But if the base class virtual function is pure, that forces the derived classes to implement the function. Hence, a pure (public) virtual function is merely an interface. I can see a benefit

Why doesn't PHP permit private constants? [duplicate]

99封情书 提交于 2019-12-04 21:11:47
This question already has an answer here: Are private constants possible in PHP? [duplicate] 4 answers Why doesn't PHP permit private const? 2 answers Why doesn't PHP permit private constants? I am aware that there are workarounds, such as using a private static property instead. However, from an OOP or software design perspective, what was the reasoning? Why doesn't PHP permit private constants? In PHP constants are part of the interface and the interface is public, always (that's what an interface is for). See as well PHP Interfaces . I'm pretty sure this is the reason design-wise. Regarding