|
-
May 13th, 2004, 06:09 AM
#1
accessing protected base class / operators
Hi !
I want derive my class as protected from its baseclass, e.g.
Code:
class CMyRect : protected CRect
{
}
because nobody should change CRect directly, but I would like to provide a possibility to get a copy of the base class, e.g.
Code:
CMyRect* p = new CMyRect();
CRect r = *p;
or even can access const methods, like
Code:
CMyRect* p = new CMyRect();
int n = p->Height();
Is there a possibility to define (an) operator(s) for this ?
Thanks in advance !
-
May 13th, 2004, 06:14 AM
#2
Not directly, but you can expost your own:
Code:
class Base
{
public:
int Hieght();
}
class Derived : protected Base
{
public:
int Hieght() { return Base::Hieght(); }
}
Remember protected inheritance means "is implemented in terms of" and not "is a". Thie means that your callers should not count on the behaviour of the base class since you may choose to implement your derived class in a different manner at any time.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
May 13th, 2004, 06:19 AM
#3
Hi !
Thanks for answering so fast !
Yes, I know that (standard) way, but I don't want to "override" all getter - methods, and I also don't want to provide a new method, like
Code:
const CRect* GetRect() const { return this; }
because the "user" of my class would always have to call
Code:
int i = p->GetRect()->Height();
Isn't there an easy way to just use an operator for the same functionality ?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|