public

Making classes public to other classes in C++

不羁的心 提交于 2019-11-29 09:05:34
问题 If I have two classes for example as follows: class A {...} class B {...} If I want to make class A public to class B , do I just make the members of class A public or I can just use public class A {...} ? Is there a way to tell class B for example that only class A is public for you? In other words, can I make public classes to A protected or private to others? Or, this is just a matter of deriving a class (inheritance)? Thanks. 回答1: There's a substantial difference between making the class

This class should be public (android.support.v7.internal.widget.ActionBarView.HomeView)

匆匆过客 提交于 2019-11-29 06:23:01
问题 I am trying to create a Android Application which uses 3 spinners. I keep getting this error and I can't figure out how to fix it. This class should be public (android.support.v7.internal.widget.ActionBarView.HomeView) 回答1: On the "v7-appcompat" library: preferences -> Android Lint Preferences Search for "Instantiatable" and set to Warning. 回答2: If you are using Eclipse: Project > Clean > OK Or Try: Preferences -> Android Lint Preferences Search for Instantiatable and set as Warning . http:/

Why does protected inheritance cause dynamic_cast to fail?

别等时光非礼了梦想. 提交于 2019-11-29 02:44:02
I changed my C++ base class to be protected inheritance and my dynamic_cast (s) stopped working. Why should changing the inheritance to protected change the behavior of dynamic_cast ? struct Base { static Base *lookupDerived(); // Actually returns a Derived * object. }; struct Derived : protected /* Switch this to public to get it working */ Base { static void test() { Base *base = lookupDerived(); if (dynamic_cast<Derived *>(base)) { std::cout << "It worked (we must be using public inheritance)." << std::endl; } else { std::cout << "It failed (we must be using protected inheritance)." << std:

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

给你一囗甜甜゛ 提交于 2019-11-29 00:32:23
问题 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

Setting public class variables

放肆的年华 提交于 2019-11-28 23:39:37
How do I set a public variable. Is this correct?: class Testclass { public $testvar = "default value"; function dosomething() { echo $this->testvar; } } $Testclass = new Testclass(); $Testclass->testvar = "another value"; $Testclass->dosomething(); marvin this is the way, but i would suggest to write a getter and setter for that variable. class Testclass { private $testvar = "default value"; public function setTestvar($testvar) { $this->testvar = $testvar; } public function getTestvar() { return $this->testvar; } function dosomething() { echo $this->getTestvar(); } } $Testclass = new Testclass

protected vs public constructor for abstract class? Is there a difference?

时光毁灭记忆、已成空白 提交于 2019-11-28 20:08:48
This question is out of curiosity. Is there a difference between: public abstract class MyClass { public MyClass() { } } and public abstract class MyClass { protected MyClass() { } } Thanks. They are the same for all practical purposes. But since you asked for differences, one difference I can think of is if you are searching for the class's constructor using reflection, then the BindingFlags that match will be different. BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; var constructor = typeof(MyClass).GetConstructor(flags, null, new Type[0], null); This will find the

How to write a simple class in C++?

萝らか妹 提交于 2019-11-28 18:34:22
I have been reading a lot of tutorials on C++ class but they miss something that other tutorials include. Can someone please show me how to write and use a very simple C++ class that uses visibility, methods and a simple constructor and destructor? TStamper Well documented example taken and explained better from Constructors and Destructors in C++ : #include <iostream> // for cout and cin class Cat // begin declaration of the class { public: // begin public section Cat(int initialAge); // constructor Cat(const Cat& copy_from); //copy constructor Cat& operator=(const Cat& copy_from); //copy

Use of “Public” in a derived class declaration?

帅比萌擦擦* 提交于 2019-11-28 18:18:31
Given this base class: class Employee { char* name; int age; public: Employee(char* name); void print(); }; With regards to the "public", what's the difference between this: class Manager : public Employee { EmployeeList employees; public: Manager(char* name, Employee* people); void print(); }; and this: class Manager : Employee { EmployeeList employees; public: Manager(char* name, Employee* people); void print(); }; The default is private inheritance. take this example: class B { }; class D: B { }; uses private inheritance as its the default. This means that D gets all the protected and

git push: permission denied (public key)

强颜欢笑 提交于 2019-11-28 16:49:53
I'm trying to push a file to a git repo of a friend but errors on public key. git push origin testbranch Permission denied (publickey). fatal: Could not read from remote repository. Where and how do we define public / private keys? git remote -v returns: origin git@github.com:Sesamzaad/NET.git (fetch) origin git@github.com:Sesamzaad/NET.git (push) Any help is appreciated. user3445140 I was facing same problem, here is what I did that worked for me. Use ssh instead of http. Remove origin if its http. git remote rm origin Add ssh url git remote add origin git@github.com:<username>/<repo>.git

Class vs. Public Class

╄→尐↘猪︶ㄣ 提交于 2019-11-28 16:35:50
问题 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 ? 回答1: 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