No, you can't do that. You can call SetBoundary() from within a member function of CTaskPlanPageHeader, but not from another class CTaskPlanPage.
I hope this can be helpful:
Code:
class base
{
private:
virtual void f() {}
protected:
virtual void g() {}
public:
virtual void h() {}
};
class derived : public base
{
protected:
void any()
{
f(); // not ok
g(); // ok
h(); // ok
}
};
class derived1 : public base
{
public:
// f() is now made public
virtual void f() {}
};
int main()
{
derived d;
d.f(); // not ok
d.g(); // not ok
d.h(); // ok
derived1 d1;
d1.f(); // ok
return 0;
}
Note I derived the CTaskPlanPage from CTaskPlanPageObject as well since the page and all objects on that page share some functionality such as SetBoundary(...).
cilu, I am not sure I understand. If I derive a class from CListCtrl for example, I can still call the base class (CListCtrl) InsertColumn(....) function
from within a view.
Mike, InsertColumn is PUBLIC. Your SetBoundary is PROTECTED. Does that tell you anything?
Originally Posted by MSDN
private
Class members declared as private can be used only by member functions and friends (classes or functions) of the class.
protected
Class members declared as protected can be used by member functions and friends (classes or functions) of the class. Additionally, they can be used by classes derived from the class.
public
Class members declared as public can be used by any function.
The problem is that you are calling SetBoundary from a derived class, but not for the current instance (this) but for another object. That doesn't work, because it's not allowed by the definition of the protected accessing rights.
To complete my example, this is exactly what you are doing...
Code:
class derived : public base
{
protected:
void any()
{
base b;
b.f(); // not ok
f(); // not ok
g(); // ok
h(); // ok
}
};
[B]
Now I left out the ctors/dtors for clarity. Also, I called SetBoundary(...) from a CTaskPlanPage object in CTaskPlan::OnInitialUpdate() to test. This compiles fine. But when I call SetBoundary() from the CTaskPlanPageHeader object, the compiler tells me it is invalid. It is public inheritance.
C:\Development\Inform2K4\TaskPlanPage.cpp(91) : error C2248: 'SetBoundary' : cannot access public member declared in class 'CTaskPlanPageObject'
C:\Development\Inform2K4\TaskPlanPageObject.h(22) : see declaration of 'SetBoundary'
Ahhh found it, sorry for wasitng your time.
I forgot to include public in the class declaration:
Code:
class CTaskPlanPageHeader : public CTaskPlanPageObject
Code:
Mike B
Right. IIRC, default inheritance between classes is private. One of the restrictions of private inheritance is that derrived objects CANNOT access protected or private members of base classes.
I'm kinda fuzzy on exactly what situations warrent protected and private inheritance (I've never really needed it). But there have been many discussions on this forum about this.
Bookmarks