[webkit-dev] initializing protected variable in a subclass
David Hyatt
hyatt at apple.com
Mon Aug 3 15:59:21 PDT 2009
Make your base class constructor take the role as an argument. Then
the subclasses can just pass in the value they want to use to
initialize it
e.g.,
AccessibilityObject(AccessibilityRole role)
: m_role(role)
{
}
and then in the subclass
AccessibilityImageMapLink()
: AccessibilityObject(WebCoreLinkRole)
{
}
Another option is to just forego the member variable storage and make
a virtual function that returns the role. That only works if the role
can be determined from the subclasses though.
virtual AccessibilityRole role() const { return WebCoreLinkRole; }
Hope this helps,
dave
(hyatt at apple.com)
On Aug 3, 2009, at 5:51 PM, Chris Fleizach wrote:
>
> I have added
>
> protected:
> AccessibilityRole m_role;
>
> to AccessibilityObject.h
>
> I want to initialize that variable in subclasses of
> AccessibilityObject, like so
>
> AccessibilityImageMapLink::AccessibilityImageMapLink()
> : m_role(WebCoreLinkRole)
>
> but the compiler says
>
>
> /Volumes/data/WebKit/WebCore/accessibility/
> AccessibilityImageMapLink.cpp:48: error: class
> ‘WebCore::AccessibilityImageMapLink’ does not have any field named
> ‘m_role’
>
> even though this works fine
>
> AccessibilityImageMapLink::AccessibilityImageMapLink()
> {
> m_role = WebCoreLinkRole;
> }
>
> any tips?
>
> thanx
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20090803/2b6b0f31/attachment.html>
More information about the webkit-dev
mailing list