代码如下:省了些无关的头文件
class  CViewView //声明
class Test  
{
public:
void GetView1( CViewView * pView);  //这个函数需要CViewView 的指针
Test();
virtual ~Test();};
实现代码。省了些无关的头文件
#include "ViewView.h" //包涵头文件
Test::Test()
{}Test::~Test()
{}void Test::GetView1(CViewView *pView)
{//在这里需要用到CViewView 
}编译错误:
 --------------------Configuration: View - Win32 Debug--------------------
Compiling...
Test.cpp
f:\vcexcample\view\viewview.h(22) : error C2143: syntax error : missing ';' before '*'
f:\vcexcample\view\viewview.h(22) : error C2501: 'CViewDoc' : missing storage-class or type specifiers
f:\vcexcample\view\viewview.h(23) : error C2501: 'GetDocument' : missing storage-class or type specifiers
f:\vcexcample\view\viewview.h(23) : warning C4183: 'GetDocument': member function definition looks like a ctor, but name does not match enclosing class
Error executing cl.exe.View.exe - 3 error(s), 1 warning(s)

解决方案 »

  1.   

    Test的头文件中#include "ViewView.h"
      

  2.   

    #include "ViewView.h"应该写在Test类的头文件里。
      

  3.   

    谢谢上面的,没用。
    我把#include "ViewView.h"
    写在了两个文件里都有错误!不信可以试一下。我搞了一上午了!
      

  4.   

    Test的头文件中还要包括#include "ViewDoc.h"
    这样的话会出什么错误?
      

  5.   

    我也包含了#include "ViewDoc.h"
    编译没错误。
    但是在视图中定义一个实例。出现错误! Test m_test;
    错误如下:做实验时把新建立一个工程,跟上面对不上了。但是不影响! 
    --------------------Configuration: Gview - Win32 Debug--------------------
    Compiling...
    Gview.cpp
    c:\program files\microsoft visual studio\myprojects\gview\test.h(16) : error C2061: syntax error : identifier 'CGviewView'
    GviewView.cpp
    c:\program files\microsoft visual studio\myprojects\gview\test.h(16) : error C2061: syntax error : identifier 'CGviewView'
    Generating Code...
    Compiling...
    Test.cpp
    c:\program files\microsoft visual studio\myprojects\gview\gviewview.h(25) : error C2146: syntax error : missing ';' before identifier 'm_test'
    c:\program files\microsoft visual studio\myprojects\gview\gviewview.h(25) : error C2501: 'Test' : missing storage-class or type specifiers
    c:\program files\microsoft visual studio\myprojects\gview\gviewview.h(25) : error C2501: 'm_test' : missing storage-class or type specifiers
    Generating Code...
    Error executing cl.exe.Gview.exe - 5 error(s), 0 warning(s)
      

  6.   

    看看是不是某个函数是保护或私有类型的,改成PUBLIC的试试,尤其是这几个类的构造函数。
      

  7.   

    :\program files\microsoft visual studio\myprojects\gview\gviewview.h
    也要包括Test.h