this is so weird - try it and see
-
Using VisualC++ 6.0 SP5 I create a new MFCAppwizard(exe) project named "my". I choose SDI with doc/view architecture support then click finish to leave all other options at their defaults. Since the project is named "my" the classes created are "CMyApp", "CMyDoc", "CMyView", "CMainFrame" and "CAboutDlg". If I build it now it will run fine so far. Then if I include the header for the CMyView class in the cpp for the CMainFrame class like so:
// MainFrm.cpp : implementation of the CMainFrame class // #include "stdafx.h" #include "my.h" #include "MainFrm.h" #include "myview.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ... ... ...
it does not compile. The 3 errors it gives are really weird: myprojects\my\myview.h(21) : error C2143: syntax error : missing ';' before '*' myprojects\my\myview.h(21) : error C2501: 'CMyDoc' : missing storage-class or type specifiers myprojects\my\myview.h(21) : error C2501: 'GetDocument' : missing storage-class or type specifiers weird, eh? I noticed that if you move the #include "myview.h" line to the top of the file (i.e. before the other three #include statements) it will compile but if you make reference to anything that was declared in myview.h it will give an error saying "undeclared identifier". For example if I wanted to create a pointer to a CMyView class within the constructor of the CMainFrame class like so:// CMainFrame construction/destruction CMainFrame::CMainFrame() { CMyView* p; }
it gives the following error messages: MyProjects\my\MainFrm.cpp(45) : error C2065: 'CMyView' : undeclared identifier MyProjects\my\MainFrm.cpp(45) : error C2065: 'p' : undeclared identifier MyProjects\my\MainFrm.cpp(45) : warning C4552: '*' : operator has no effect; expected operator with side-effect (remember that is with the #include "myview.h" moved to the very top of the mainfrm.cpp file anybody know why it doesn't like what I'm trying to do? I'm a bit new at this and I searched the forum for someone asking the same question but didn't find anything relevant. thanks! -Oinka -
Using VisualC++ 6.0 SP5 I create a new MFCAppwizard(exe) project named "my". I choose SDI with doc/view architecture support then click finish to leave all other options at their defaults. Since the project is named "my" the classes created are "CMyApp", "CMyDoc", "CMyView", "CMainFrame" and "CAboutDlg". If I build it now it will run fine so far. Then if I include the header for the CMyView class in the cpp for the CMainFrame class like so:
// MainFrm.cpp : implementation of the CMainFrame class // #include "stdafx.h" #include "my.h" #include "MainFrm.h" #include "myview.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ... ... ...
it does not compile. The 3 errors it gives are really weird: myprojects\my\myview.h(21) : error C2143: syntax error : missing ';' before '*' myprojects\my\myview.h(21) : error C2501: 'CMyDoc' : missing storage-class or type specifiers myprojects\my\myview.h(21) : error C2501: 'GetDocument' : missing storage-class or type specifiers weird, eh? I noticed that if you move the #include "myview.h" line to the top of the file (i.e. before the other three #include statements) it will compile but if you make reference to anything that was declared in myview.h it will give an error saying "undeclared identifier". For example if I wanted to create a pointer to a CMyView class within the constructor of the CMainFrame class like so:// CMainFrame construction/destruction CMainFrame::CMainFrame() { CMyView* p; }
it gives the following error messages: MyProjects\my\MainFrm.cpp(45) : error C2065: 'CMyView' : undeclared identifier MyProjects\my\MainFrm.cpp(45) : error C2065: 'p' : undeclared identifier MyProjects\my\MainFrm.cpp(45) : warning C4552: '*' : operator has no effect; expected operator with side-effect (remember that is with the #include "myview.h" moved to the very top of the mainfrm.cpp file anybody know why it doesn't like what I'm trying to do? I'm a bit new at this and I searched the forum for someone asking the same question but didn't find anything relevant. thanks! -OinkaOinka wrote: myprojects\my\myview.h(21) : error C2143: syntax error : missing ';' before '*' myprojects\my\myview.h(21) : error C2501: 'CMyDoc' : missing storage-class or type specifiers myprojects\my\myview.h(21) : error C2501: 'GetDocument' : missing storage-class or type specifiers There are two solutions to this problem. 1. Add #include "MyDoc.h" before the "MyView.h" include 2. Forward declare CMyDoc in the MyView.h header file. Michael 'Logic, my dear Zoe, merely enables one to be wrong with authority.' - The Doctor: The Wheel in Space
-
Oinka wrote: myprojects\my\myview.h(21) : error C2143: syntax error : missing ';' before '*' myprojects\my\myview.h(21) : error C2501: 'CMyDoc' : missing storage-class or type specifiers myprojects\my\myview.h(21) : error C2501: 'GetDocument' : missing storage-class or type specifiers There are two solutions to this problem. 1. Add #include "MyDoc.h" before the "MyView.h" include 2. Forward declare CMyDoc in the MyView.h header file. Michael 'Logic, my dear Zoe, merely enables one to be wrong with authority.' - The Doctor: The Wheel in Space
I tried solution #1 and it works fine now, but I'm still confused about why that is necessary. Why do I have to include the doc class declaration in order to use the view class? Shouldn't the view class header just include everything it needs for itself? thanks again -Oinka
-
I tried solution #1 and it works fine now, but I'm still confused about why that is necessary. Why do I have to include the doc class declaration in order to use the view class? Shouldn't the view class header just include everything it needs for itself? thanks again -Oinka
Oinka wrote: Why do I have to include the doc class declaration in order to use the view class? Shouldn't the view class header just include everything it needs for itself? The CView derived class has a GetDocument function. I assume there is some MFC design reason why the include file or forward declaration isn't generated by the AppWizard. (Or it could be an oversight by the MFC team not realising how developers were going to structure their code) Michael 'Logic, my dear Zoe, merely enables one to be wrong with authority.' - The Doctor: The Wheel in Space