|
I know that the derived class can't access the private members of the base class, so why does the derived class inherit the private members of the base class? Is there any case that it is useful?
Thanks!
Started by skydoor on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
The derived class....
So I don't even know what you mean.
The derived class doesn't "inherit" the private members of the base class in any way - it can't of the private members of the base class, for obvious reasons.
|
|
Let's say I have a very simple PrototypeJS class that looks like this:
var Foo = Class.create({ initialize: function() { this.bar = 'bar'; }, dostuff: function() { $$('.enabled').each( function(elem) { alert(this.bar); //FAIL }); } });
This fails because...
Started by Mark Biek on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Var Foo = Class.create({ bar : "bar", dostuff.
Instance of the class, replace all this's with Foo.
|
|
I'm having trouble implementing a nested class who's constructor is initialized with some of the enclosing class' private data members.
Example:
Header File: class Enclosing { //...Public members //...Private members int x, int y class Inner; // Declaration...
Started by trikker on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
So, whether you have to do of the Inner class....
To give the inner class the necessary privileges (friendship) or expose the members x and y classes should have full access to outer class members (even private ones).
|
Ask your Facebook Friends
|
I have instances of class A and B, and both classes implement a member 'Text'. Is there a way to access member Text in a generic way? I'm hoping for something analogous to the javascript way of simply saying:
instance['Text'] = value;
Note: these two ...
Started by Protector one on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Probably or base class you could....
Ideally you should have single class with member "Text" which will be base for A and B.
Then you need to use reflection to access any class member by name, something like this:
typeof.
|
|
I observed that Outer classes can access inner classes private instance variables. How is this possible? A sample code demonstrating the same is explained below::
class ABC{ class XYZ{ private int x=10; } public static void main(String... args){ ABC.XYZ...
Started by Harish on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
It this stands to reason....
Since they're basically a member declared in a class to not be able to access all of the instance/class members.
These requirements, inner classes have full access to their outer class.
|
|
Say I have a class that looks something like this:
class SomeClass { int m_member; public int Member { get { return m_member; } set { m_member = value; } } }
And somewhere else, I have a list of type List<SomeClass> list .
If I want to search the...
Started by Matthew on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Int index = list.FindIndex(m => m.Member == someMember);
If you can use Linq
SomeClass aClasss = list.FirstOrDefault(item => item.Member == someMember); .
|
|
Hi,
I have a question regarding vectors:
If I have a std::vector<MyClass> will this vector "inherit" the MyClass member functions or not? If not, then would be the best way to handle individually the MyClass members inside a loop? Would I have to...
Started by nmuntz on
, 11 posts
by 11 people.
Answer Snippets (Read the full thread at stackoverflow):
V; endl; }
The vector inherits nothing from its class, but the members are members of the classNo....
Then you can call those functions on your objects.
Or the at() member functions to access your class objects.
|
|
Is this scenario even possible?
class Base { int someBaseMemer; }; template<class T> class Derived : public T { int someNonBaseMemer; Derived(T* baseInstance); };
Goal:
Base* pBase = new Base(); pBase->someBaseMemer = 123; // Some value set Derived...
Started by AOI Karasu on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Use inheritance to do the job for you:
class Base { public: Base(int x) : someBaseMemer(x) {} protected: ....
A struct provides public stops you from having both.
That a class has private access to all members and methods by default.
|
|
Hi there,
I am having a couple of issues deciding how best to describe a certain data structure in C# (.NET 3.5).
I have to create a class library that creates some text files for the input of a command line program. There are dozens of file types, but...
Started by Alex on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Forcing the derived class to supply the details, consider an abstract property that the derived class must provide:
// base-class public abstract FileType FileType {get;} // derived-class....
As you say, constructors are not inherited.
|
|
I have a code:
class AbstractQuery { virtual bool isCanBeExecuted()=0; public: AbstractQuery() {} virtual bool Execute()=0; }; class DropTableQuery: public AbstractQuery { vector< std::pair< string, string> > QueryContent; QueryValidate qv...
Started by chester89 on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
No, in fact for it is unnecessary for the base class to have an explicitly defined constructor like this:
class MyInterface { public: virtual ~MyInterface() {} virtual void execute() = 0; };
EDIT destructor
No, not in the example you provided....
|