Sternocera

Hello,


I'm following a tutorial on creating a splitter-window based application, with navigational controls on the left hand pane ( a treeview) and a CFrameWnd derived frame on the right hand side.


It is at http://www.codeguru.com/cpp/w-d/splitter/article.php/c1549/


I'd like to vary what view the frame displays, based on user input into the treeview pane, per the tutorial.


I've attempted to reconcile the tutorials source with my own wizard-generated MFC application's explorer-style (splitter window) source. For example, while the wizard generated code instantiates all views through the RUNTIME_CLASS macro, in the tutorial, views are instantiated on the heap using the new operator, so I've changed my code accordingly. I've made my view class's constructor public rather then protected, so that it could be instantiated in this way.


However, I still get this compile time error message:


1>c:\documents and settings\user\my documents\visual studio 2005\projects\lustre\lustre\rightpaneframe.cpp(36) : error C2248: 'CFormView::Create' : cannot access protected member declared in class 'CformView'

1> c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxext.h(802) : see declaration of 'CFormView::Create'

1> c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxext.h(750) : see declaration of 'CFormView'


I've attempted to access the member from my CFr
ameWnd derived class where the view class is instantiated.


It is not apparent to me, from viewing the tutorial's source, how they've overcome this problem.


Could anyone offer an opinion as to how they have avoided this error


Thanks a lot



Re: Visual C++ Language MFC: cannot access protected member of a MFC class

einaros

That tutorial was written in 1998, so chances are a lot has happened since. Have you seen through other sites, such as Codeproject.com, for articles http://www.codeproject.com/wtl/wtl4mfc7.asp shows how to use splitter windows, in a relatively new version of the MFC.




Re: Visual C++ Language MFC: cannot access protected member of a MFC class

Sternocera

This tutorial is for the windows template library, not MFC at all, though it is orientated towards MFC programmers. I don't want to change paradigms. I have only a single compile time error, which is probably trivial enough to solve.

I speculate that this error is due to the fact that Microsoft fully implemented the ANSI C++ standard in Visual studio .net 2003, after the tutorial was produced . However, I can convert the tutorial solution into a 2005 solution, and it compiles fine - perhaps Visual studio knows to implement some override when converting a pre 2003 solution Perhaps I can manually switch on this override for my own project





Re: Visual C++ Language MFC: cannot access protected member of a MFC class

Nishant Sivakumar

Are you using the latest WTL release If so, it may not be compatible with pre-2005 compilers - a lot has changed from VC6 to VC2003 and then again a few more changes between 2003 and 2005.





Re: Visual C++ Language MFC: cannot access protected member of a MFC class

Sternocera

Nishant,

I'm not using WTL at all - I'm using Microsoft foundation classes with visual studio 2005.




Re: Visual C++ Language MFC: cannot access protected member of a MFC class

Nishant Sivakumar

Sternocera wrote:
Nishant,

I'm not using WTL at all - I'm using Microsoft foundation classes with visual studio 2005.


I apologize - I got mis-directed on reading your previous reply (where you mentioned that the article was on WTL - though you were referring to the other poster's URL).

Could you copy/paste the code snippet that's giving you the error

MFC sources have had a few breaking changes between VC 2003 and VC 2005. Perhaps what you are seeing is due to one of them.





Re: Visual C++ Language MFC: cannot access protected member of a MFC class

Sternocera

Code SnippetBOOL CRightPaneFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{

m_pLustreView = new CLustreView;
m_pLustreView->Create(NULL, NULL, 0L, CFrameWnd::rectDefault, this,
VIEW_LUSTRE, pContext);
SetActiveView(m_pLustreView);
m_pLustreView->ShowWindow(SW_SHOW);
m_pLustreView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);

RecalcLayout();

return TRUE;

}
Here is the function that causes the problem. It's only a snippet of code, as I like to make small parts work (or at least compile) in isolation, to track down problems. The problem is that I cannot instantiate a CLustreView class on the heap with the new operator because its MFC base class, CFormView, has a protected constructor, among other things. MFC wizard generated projects have, by default, view classes instantiated by DYNCREATE ("Serialization") .However, I can still compile the converted tutorial project fine, though I don't know why.




Re: Visual C++ Language MFC: cannot access protected member of a MFC class

Nishant Sivakumar

I think your problem is that CLustreView has a protected constructor. Change its constructor to public (it doesn't matter if CFormView's ctor is protected).





Re: Visual C++ Language MFC: cannot access protected member of a MFC class

Sternocera

Nishant,

That was a problem, but one that was quickly solved. As you can see from the compiler output:

c:\documents and settings\user\my documents\visual studio 2005\projects\lustre\lustre\rightpaneframe.cpp(37) : error C2248: 'CFormView::Create' : cannot access protected member declared in class 'CFormView'

CFormView's Create function is mentioned explicitly. The create function, as well as the constructor are protected. I cannot just make CLustreView a friend of CFormView, as its implementation is object code.

Thanks




Re: Visual C++ Language MFC: cannot access protected member of a MFC class

Nishant Sivakumar

The main issue here is that you are trying to use CFormView in a way it wasn't designed for. So you'd have to work around it in what some may consider an inelegant manner. Which would be to override Create in your CLustre class (make that public) and merely call the base class implementation.

CLustre::CReate(...)
{
return CFormView::CReate(...);
}





Re: Visual C++ Language MFC: cannot access protected member of a MFC class

Sternocera

Nishant,
I tried your suggestion. It worked. Thank you so much. I'm very grateful,

Regards,
Sternocera

For the benefit of anyone who might find this post in the future, here is the actual code:

Code Snippet

BOOL CLustreView::Create(LPCTSTR A, LPCTSTR B, DWORD C,
const RECT& D, CWnd* E, UINT F, CCreateContext* G)
{
return CFormView::Create(A, B, C, D, E, F, G);
}






Re: Visual C++ Language MFC: cannot access protected member of a MFC class

Julien Lemaitre

Hi,

So, what is the correct way to create a CFormView-derived class

Especially to create a CFormView nested inside another window (inside a CView or CWnd...)

Thanks,
Julien