我下了一个五子棋人机对弈的VC程序,想在菜单里加个可设置人机执先顺序的功能,于是就在  MainFrm.cpp  里多了两个消息响应函数,编写这两个函数的时候要用到在  CEx_playView.h  里定义的两个变量,我在  MainFrm.cpp  里加了#include "CEx_playView.h",也声明了这两个变量,编译能通过,但是执行的时候报错,说是无法解析的外部符号,请问是怎么回事啊,应该怎么解决,当然在CEx_playView.cpp里也用到了这两个变量,是两个文件共用所以乱了吗

解决方案 »

  1.   

    我在 MainFrm.cpp 里加了#include "CEx_playView.h",也声明了这两个变量这个extern就可以了吧 不需要再声明了吧
      

  2.   

    这是两个消息响应函数:
    void CMainFrame::OnMe() 
    {
    // TODO: Add your command handler code here
    for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
    wzq[i][j]=0;
    colorwhite=true;
    Invalidate();
    }void CMainFrame::OnConputer()  
    {
    // TODO: Add your command handler code here
    for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
    wzq[i][j]=0;
    colorwhite=false;
    Invalidate();
    }
      

  3.   

    // CEx_playView.h : interface of the CEx_playView class
    //
    /////////////////////////////////////////////////////////////////////////////#if !defined(AFX_CEx_playVIEW_H__9FBADA6D_CAD7_11D5_B2C4_5254AB2BD63E__INCLUDED_)
    #define AFX_CEx_playVIEW_H__9FBADA6D_CAD7_11D5_B2C4_5254AB2BD63E__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    class CEx_playView : public CView
    {
    protected: // create from serialization only
    CEx_playView();
    DECLARE_DYNCREATE(CEx_playView)// Attributes
    public:
    CEx_playDoc* GetDocument();// Operations
    public:// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CEx_playView)
    public:
    virtual void OnDraw(CDC* pDC);  // overridden to draw this view
    virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
    protected:
    virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
    virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
    virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
    //}}AFX_VIRTUAL// Implementation
    public:
    void Save();
    void over(CPoint point);
    HCURSOR hcursorwhite;
    HCURSOR hcursorblack;
    int wzq[3][3];
    bool colorwhite;
    CBitmap m_bmblack;
    CBitmap m_bmwhite;
    virtual ~CEx_playView();
    #ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
    #endifprotected:// Generated message map functions
    protected:
    //{{AFX_MSG(CEx_playView)
    afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
    afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
    afx_msg void OnStart();
    afx_msg void OnSave();
    afx_msg void OnOpen();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };#ifndef _DEBUG  // debug version in CEx_playView.cpp
    inline CEx_playDoc* CEx_playView::GetDocument()
       { return (CEx_playDoc*)m_pDocument; }
    #endif///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_CEx_playVIEW_H__9FBADA6D_CAD7_11D5_B2C4_5254AB2BD63E__INCLUDED_)// MainFrm.cpp : implementation of the CMainFrame class
    //
    #include "CEx_playView.h"
    #include "stdafx.h"
    #include "CEx_play.h"#include "MainFrm.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    extern bool colorwhite;
    extern int wzq[3][3];
    extern class CEx_playView CView;
    /////////////////////////////////////////////////////////////////////////////
    // CMainFrameIMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
    //{{AFX_MSG_MAP(CMainFrame)
    ON_WM_CREATE()
    ON_COMMAND(ID_ME, OnMe)
    ON_COMMAND(ID_CONPUTER, OnConputer)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()static UINT indicators[] =
    {
    ID_SEPARATOR,           // status line indicator
    ID_INDICATOR_CAPS,
    ID_INDICATOR_NUM,
    ID_INDICATOR_SCRL,
    };/////////////////////////////////////////////////////////////////////////////
    // CMainFrame construction/destructionCMainFrame::CMainFrame()
    {
    // TODO: add member initialization code here

    }CMainFrame::~CMainFrame()
    {
    }int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
    return -1;

    if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
    | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
    !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
    {
    TRACE0("Failed to create toolbar\n");
    return -1;      // fail to create
    } if (!m_wndStatusBar.Create(this) ||
    !m_wndStatusBar.SetIndicators(indicators,
      sizeof(indicators)/sizeof(UINT)))
    {
    TRACE0("Failed to create status bar\n");
    return -1;      // fail to create
    } // TODO: Delete these three lines if you don't want the toolbar to
    //  be dockable
    m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
    EnableDocking(CBRS_ALIGN_ANY);
    DockControlBar(&m_wndToolBar);
        //添加白棋图像
    // m_wndStatusBar.GetStatusBarCtrl().SetIcon(0,AfxGetApp()->LoadIcon(IDI_WHITE));
    //显示文字
    // m_wndStatusBar.SetPaneText(0,"白棋下");
        
    return 0;
    }BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
    {
    if( !CFrameWnd::PreCreateWindow(cs) )
    return FALSE;
    // TODO: Modify the Window class or styles here by modifying
    //  the CREATESTRUCT cs
    cs.dwExStyle=cs.dwExStyle|WS_EX_TOPMOST; //
    cs.style=WS_SYSMENU|WS_OVERLAPPED|WS_MINIMIZEBOX;//; 
    //设置窗口大小:400*340
    cs.cx=250;
    cs.cy=335;   
    return TRUE;
    }/////////////////////////////////////////////////////////////////////////////
    // CMainFrame diagnostics#ifdef _DEBUG
    void CMainFrame::AssertValid() const
    {
    CFrameWnd::AssertValid();
    }void CMainFrame::Dump(CDumpContext& dc) const
    {
    CFrameWnd::Dump(dc);
    }#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////
    // CMainFrame message handlersvoid CMainFrame::OnMe() 
    {
    // TODO: Add your command handler code here
    for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
    CView->wzq[i][j]=0;
    CView->colorwhite=true;
    Invalidate();
    }void CMainFrame::OnConputer()  
    {
    // TODO: Add your command handler code here
    for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
    CView->wzq[i][j]=0;
    CView->colorwhite=false;
    Invalidate();
    }