protected

Problem with protected fields in base class in c++

I have a base class, say BassClass, with some fields, which I made them protected, and some pure virtual functions. Then the derived class, say DerivedClass, like class DerivedClass : public BassClass. Shouldn't DerivedClass inherit the protected fields from BassClass? When I tried to compile the DerivedClass, the compiler complains that...

C# protected members accessed via base class variable

Hello. It may seems rather newbie question, but can you explain why method Der.B() cannot access protected Foo via Base class variable? This looks weird to me: public class Base { protected int Foo; } public class Der : Base { private void B(Base b) { Foo = b.Foo; } // Error: Cannot access protected member private void D(D...

What's the real reason for preventing protected member access through a base/sibling class?

I recently discovered that a method in a derived class can only access the base class's protected instance members through an instance of the derived class (or one of its subclasses): class Base { protected virtual void Member() { } } class MyDerived : Base { // error CS1540 void Test(Base b) { b.Member(); } // error CS...

AS3: overriding protected var in subclass

Hi all, I'm having a blackout here. I thought I understood these principles, but I can't seem to get it working anymore. I want to let a DeleteButton inherit from a general Button class. This DeleteButton should alter the protected padding values and have a static label. This is what I have: public class Button { private var _label...

C# set accessor accessible to all types in assembly, and get assessor only to derivated types. How to?

This property in a type with no access modifier (thus internal access): class SomeType { private int length; internal int Length { get { return length; } set length = value; } } } allows all types within the assembly of SomeType to use get and set accessors. Problem: how to restrict the access to set to onl...

Favorite C++ template hack

Templates are both the blessing and curse of C++. Someone hates them, someone loves them. For those of you are in the latter group, whats your favorite template "hack", and what does it do? I'll start with my personal favorite, the "friender". This template allowes access to protected members - which I very frequently use for unittestin...

Can I make a protected member public in Java? I want to access it from a subclass

Hi, I'm new to Java and OOP, I was using a private subclass (actually a struct) B in a class A, and everything went well until I decided to make a parent class C for subclass B. I want make public some of the protected members of class C. For example: public class A { private class B extends C { public int product; ...

What's the difference between an abstract class, and a class with only protected constructors? (.NET)

What are all the difference between an abstract class, and a class with only protected constructor(s)? They seem to be pretty similar to me, in that you can't instantiate either one. EDIT: How would you create an instance in a derived class, with a base class with a protected constructor? For instance: public class ProtectedConstr...

Help to understand the issue with protected method

I'm reading Sybex Complete Java 2 Certification Study Guide April 2005 (ISBN0782144195). This book is for java developers who wants to pass java certification. After a chapter about access modifiers (along with other modifiers) I found the following question (#17): True or false: If class Y extends class X, the two classes are in ...

Why is Java's AbstractList's removeRange() method protected?

Does anyone have any idea, why removeRange method in AbstractList (and also in ArrayList) is protected? It looks like a quite well-defined and useful operation, but still, to use it, we're forced to subclass the List implementation. Is there some hidden rationale? Seems quite inexplicable to me. ...

Java protected modifier not working as expected

I have the following two files: Fruit.java: package superClass; public class Fruit { protected static void printName() { System.out.println("My name is Khan"); } } Apple.java: package food; import superClass.*; public class Apple { public static void main(String[] args) { int i, j; for(i = 0; i < 5; i++) { for(j = ...

Ruby private instance variables, with exceptions

I am making a card game in ruby. I have the Game class, which has an array of Player objects. array_of_players = Array[ Player.new("Ben"), Player.new("Adam"), Player.new("Peter"), Player.new("Fred"), ] my_game = Game.new(array_of_players) puts my_game.players[2].name #=> Peter Each player also has access to the Game, so ...

One question about protected constructor

One question about protected constructor. I learnt that the protected constructor can be used in the derived class. How ever, I found the code below has an error. Why does it happen like this? class A { protected: A(){} }; class B: public A { public: B() { A* f=new A(); // Why it is not wor...

c# wrapper and issue with protected memory.

So I've now progressed to having an almost functioning wrapper. Other posts regarding my wrapper issues are: http://stackoverflow.com/questions/2430089/c-wrapper-and-callbacks & http://stackoverflow.com/questions/2444687/c-wrapper-for-array-of-three-pointers I use the wrapper to establish a connection to the Dallmeier using the follow...

How Can I have a Flash AS3 Projector load protected content?

How Can I have a Flash AS3 Projector load protected images/mp3s/videos from a password protected server? I have a bunch of content in a password protected directory that I do not want people to access unless it is in my flash Projector. Is this possible? ...

Java: Protected classes?

I'd like to be able to have two protected classes in my package. That is, I do not want files outside of my package to see them as visible - they will be for internal use within the package only. How can I do this? ...

Why protected superclass member cannot be accessed in a subclass function when passed as an argument?

I get a compile error, which I'm slightly confused about. This is on VS2003. error C2248: 'A::y' : cannot access protected member declared in class 'A' class A { public: A() : x(0), y(0) {} protected: int x; int y; }; class B : public A { public: B() : A(), z(0) {} B(const A& item) : A(), z(1) { x = item.y;} private: int z...

What does it means? [c#]

If we define a property as public property and in this property we have a protected getter. what does it means? if property is public, what does defining a protected getter for that, means? please see below code: public ISessionFactory SessionFactory { protected get { return sessionFactory; } set { sessionFactory...

Protected members in a superclass inaccessible by indirect subclass in Java

Why is it that in Java, a superclass' protected members are inaccessible by an indirect subclass in a different package? I know that a direct subclass in a different package can access the superclass' protected members. I thought any subclass can access its inherited protected members. EDIT Sorry novice mistake, subclasses can access a...

What do you choose, protected or internal?

If I have a class with a method I want protected and internal. I want that only derived classes in the assembly would be able to call it. Since protected internal means protected or internal, you have to make a choice. What do you choose in this case - protected or internal? ...