Re: Cannot access protected from base class?
On Sep 24, 10:56 pm, Richard Damon <news.x.richardda...@xoxy.net>
wrote:
On 9/24/11 8:24 PM, Nephi Immortal wrote:
On Sep 24, 7:14 pm, Richard Damon<news.x.richardda...@xoxy.net>
wrote:
On 9/24/11 5:03 PM, Nephi Immortal wrote:
I discussed functionoids and pointer to member functions a lo=
ng time
ago. The template is the best option over functionoids because of =
the
performance issue. Unfortunately, template does not support pointe=
r
to member function array.
I am surprised to see that C++ Compiler reports an error to s=
ay any
member function cannot access to protected from base class, but
ordinary function worked. Very absurb?
A derived class can only access the protected parts of a base camp
through the derived class, not directly from the base camp.
In your example, rather than using Obj1::run, use Obj::run. since Obj
has inherited them, it can access them there.
I will also add that this structure seems awkward. While having a larg=
e
number of base classes is allowed, it feels like inheritance is being
forced in a place where it really doesn't fit.
I understand, but I wonder if large number of base classes violate
rule and needs to make sure if more memory is sufficient.
A large number of base classes do not violate an inherent rule in C++.
You will likely end up with a large object, as it needs to store all the
base class members within it. It is possible that this may cause you to
run out of memory, it somewhat depends on how many copies of this object
are created.
I do think it is a sign of a problematical design.- Hide quoted text -
- Show quoted text -
I am aware of design flaw, but careful design is better. Large
number of base classes into one derived class is the option to replace
virtual functions because of the performance issue and template is not
the option unless you want pointer to member function array.
All member functions in each base class should be static. The
derived class will allocate approximately 4K to 32K memory if memory
contains derived class' pointer and array of indirect pointers.
You can always create many copies of derived objects, but static
member functions are shared by derived objects. You create interface
class. It includes one derived object definition in the class body.
The client can select the number of objects before interface does the
job to process the derived object such as command object.
For example:
class Interface
{
public:
void Run( int index )
{
cmdList.Execute( index );
}
private:
derivedObject cmdList;
};
If you think that it is design flaw, please demonstrate another
option.