[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: OT: C++ question
From: Tobias Anton <anton () stud ! fbi ! fh-darmstadt ! de>
Date: 2001-03-31 2:42:08
[Download RAW message or body]
On Wednesday 28 March 2001 21:18, Malte Starostik wrote:
> Hi,
>
> I have something like this:
>
> namespace Config { class Node; }
>
> class ConfigListItem : public QListViewItem
> {
> public:
> ConfigListItem(QListViewItem *parent, QListViewItem *after,
> Config::Node *node);
>
> protected:
> Config::Node *m_node;
> };
>
> class ChoiceListItem : public ConfigListItem
> {
> public:
> ChoiceListItem(ConfigListItem *parent, QListViewItem *after, int index)
>
> : ConfigListItem(parent, after, parent->m_node) {};
>
> };
>
> and g++ complains:
> In file included from /home/malte//src/kde/kdeadmin/kcmlinuz/main.cpp:28:
> /home/malte/src/kde/kdeadmin/kcmlinuz/configlist.h: In method
> `ChoiceListItem::ChoiceListItem(ConfigListItem *, QListViewItem *, int)':
> /home/malte/src/kde/kdeadmin/kcmlinuz/configlist.h:53: `class Config::Node
> * ConfigListItem::m_node' is protected
> /home/malte/src/kde/kdeadmin/kcmlinuz/configlist.h:60: within this context
>
> Actually I thought a subclass could access protected members of the base
> class? But g++ only accepts the aboce code when I add friend class
> ChoiceListItem to ConfigListItem's declaration.
an object of a subclass may access members of its own base class, but it may
not access that base class inherited by other objects.
notice the little difference between this->some_protected_baseclass_member
and parent->some_protected_base_class_member
i.e. if you have a class structure like:
bob: public alice
clarice : public alice
clarice::some_function()
{
// may not access:
bob->inherited_protected_member
}
... even though bob could redeclare the inherited_protected_member private.
i don't understand the reason for this, though.
Cheers,
Tobias
>> Visit http://master.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic