public

C++ why use public, private or protected inheritance?

廉价感情. 提交于 2019-11-30 05:05:44
Well there is enough information about this subject. For example this thread was very clear to me: Difference between private, public, and protected inheritance Except one point; Why is it useful? Use public inheritance to reflect an is-a relationship . This is the main use for inheritance, especially in combination with virtual functions. It allows re-use of interface, not just of old code by new code, but also re-use of new code by old code! (because of virtual function dispatch at runtime). In exceptional circumstances, use private inheritance to reflect an is-implemented-in-terms-of

Can there be two public section in a class? If yes then why ? And in which circumstances we do so?

为君一笑 提交于 2019-11-30 03:40:50
There is something bugging me about classes. For example class A { public: A() { ..... ..... } void cleanup() { .... .... .... } public: UINT a; ULONG b; }; In the above example there are two public section. In the first section I am defining a constructor and a method and in the second section I am declaring data members. Is the above class i.e. A correct. Can we do that? If yes then why is that needed and in what circumstances should we use it? Since we can do the entire thing in one section then why are there two sections? Access qualifiers simply apply to the code that follows until the

How do I make an Rust item public within a crate, but private outside it?

£可爱£侵袭症+ 提交于 2019-11-30 03:01:40
I have a crate that has lots of code, so I've split it into multiple files/modules. However, some modules have internal unsafe stuff (e.g. raw pointers) that I need to make public to the different modules, but I don't want to expose to users of my crate. How can I do that? The only way I can think of is to actually have my crate just be one big module, but then there's no way to split it into different files, other than this solution which seems a bit hacky. Normally when I come up against a real world problem that the simple examples in the Rust docs don't adequately explain I just copy a

Class vs. Public Class

不问归期 提交于 2019-11-29 20:33:48
What is the difference between: namespace Library{ class File{ //code inside it } } and: namespace Library{ public class File{ //code inside it } } So what will be the difference between public class and class ? Without specifying public the class is implicitly internal . This means that the class is only visible inside the same assembly. When you specify public , the class is visible outside the assembly. It is also allowed to specify the internal modifier explicitly: internal class Foo {} The former is equivalent to: namespace Library{ internal class File{ //code inside it } } All

'public static final' or 'private static final' with getter?

柔情痞子 提交于 2019-11-29 19:59:03
In Java, it's taught that variables should be kept private to enable better encapsulation, but what about static constants? This: public static final int FOO = 5; Would be equivalent in result to this: private static final int FOO = 5; ... public static getFoo() { return FOO; } But which is better practice? There's one reason to not use a constant directly in your code. Assume FOO may change later on (but still stay constant), say to public static final int FOO = 10; . Shouldn't break anything as long as nobody's stupid enough to hardcode the value directly right? No. The Java compiler will

C# override public member and make it private

萝らか妹 提交于 2019-11-29 17:46:03
问题 Possible? Can you change the access of anything to anything else? 回答1: No, you can hide a public member with a private method in a subclass, but you cannot override a public member with a private one in a subclass. And, in actually, it's not just a public/private thing, this applies to narrowing the access in general. Revised : By hiding with a more restrictive access - in this case private access - you will still see the base class member from a base-class or sub-class reference, but it

“The constructor is not visible” error

≡放荡痞女 提交于 2019-11-29 15:00:07
I have two classes : First, with one constructor : public class First { First (ObjectA myObjectA) { //do stuff } } And Second, with two constructors : public class Second { Second (ObjectB myObjectB) { //do something... } Second (ObjectC myObjectC) { //do something else... } } When I want to instantiate my First class, Eclipse generates me an error ("The constructor is not visible"), I have to add public to the constructor of First : First first = new First(myObject); //Error : "The constructor is not visble" But when I instantiate my Second class, I have no error : Second second = new Second

How to get the public IP address of the device

假装没事ソ 提交于 2019-11-29 14:29:24
问题 I found this sample code to get all local IP addresses, but I don't find an easy solution to get the public IP. A legacy class from Apple allowed to do that ... but it's legacy ... 回答1: I have used ALSystemUtilities in the past. You basically have to make a call externally to find this out. + (NSString *)externalIPAddress { // Check if we have an internet connection then try to get the External IP Address if (![self connectedViaWiFi] && ![self connectedVia3G]) { // Not connected to anything,

How to access an object's public fields from a Velocity template

橙三吉。 提交于 2019-11-29 13:25:43
Here is my object class: public class Address { public final String line1; public final String town; public final String postcode; public Address(final String line1, final String town, final String postcode) { this.line1 = line1; this.town = town; this.postcode = postcode; } } I add it to the velocity context like this: Address theAddress = new Address("123 Fake St", "Springfield", "SP123"); context.put("TheAddress", theAddress); However, when writing the template, the following will not render the address fields (however, it works fine when I add getters to the Address class) <Address> <Line1

Run a script.php on cron job on linux/apache server but restrict public access to the php file

╄→гoц情女王★ 提交于 2019-11-29 10:48:45
I have this script.php file which i want to run as a cron job on my linux/apache server. However, i do not want public to access www.mycompanyname.com/script.php and also run the script concurrently. How can we prevent that? How can we restrict the script to the server's access only? Is it using chmod or setting something inside .htaccess file, something along the line? Any advice ? You probably have something like a public_html directory, in which you have all the phps. Just put it outside of that directory. You can do this as the first line of PHP in script.php ... if (PHP_SAPI !== 'cli') {