|
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.
|
|
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).
|
|
Im programming in C#.NET. I want to create a nested class that can access members of the instance that created it but I can't seem to figure out how.
This is what I want to do:
Car x = new Car() x.color = "red"; x.Door frontDoor = new x.Door(); MessageBox...
Started by Jordan S on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Want to be able to access the private members of Car in the door class you need to use inheritance, if you just want to access the public members of Car inside the Door class you can use Composition:
class Car { public....
|
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.
|
|
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.
|
|
When creating decorators for use on class methods, I'm having trouble when the decorator mechanism is a class rather than a function/closure. When the class form is used, my decorator doesn't get treated as a bound method.
Generally I prefer to use the...
Started by Alphabet Soup on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
For example, if you had tried manually annotating the class, you would have realised.
The problem.
|
|
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....
|
|
In C++, why is private the default visibility for members of classes, but public for structs?
Started by S I on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Because a class....
A whole lot of C code were introduced in C++, and to conform with the OO philosophy of encapsulation, their members are private by default.
Carried over from C, where the semantics of their members was that of public.
|
|
Is there any way other than using reflection to access the members of a anonymous inner class?
Started by sarav on
, 8 posts
by 8 people.
Answer Snippets (Read the full thread at stackoverflow):
The best way would be....
Mr Fooz is right, except that interfaces can only define constant members.
If it implements an interface or extends an existing class, you can access the members defined in the interface or base class.
|
|
Is there some software for visual studio to automatically group c# class members?
Started by Ronnie Overby on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
The developer to quickly find solution files, types, particular type members, methods or properties.
|