Re: [webkit-dev] initializing protected variable in a subclass

2009-08-03 Thread David Hyatt
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
(hy...@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@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev


___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev


[webkit-dev] initializing protected variable in a subclass

2009-08-03 Thread Chris Fleizach


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@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev