程序员家园论坛软件开发Visual C++编程技术 unresolved external symbol "class CCommand * m_pCmd&quo

1  /  1  页   1 跳转 查看:865

unresolved external symbol "class CCommand * m_pCmd&quo

unresolved external symbol "class CCommand * m_pCmd&quo

在文档的菜单命令响应函数中需要使用视图类的CCommand* m_pCmd命令对象,因此在视图类头文件中将该对象设置为全局类对象,并在文档类中使用:
void CMyCADDoc:nPick()
{
// TODO: Add your command handler code here
// 如果当前状态存在命令,那么
// 1. 取消该命令的操作
// 2. 删除该命令对象
// 3. 将命令指针设为空
if( m_pCmd ){
  m_pCmd->Cancel();
  delete m_pCmd ;
  m_pCmd = NULL;
}
}
结果出现编译错误:
MyCADDoc.obj : error LNK2001: unresolved external symbol "class CCommand * m_pCmd" (?m_pCmd@@3PAVCCommand@@A)
MyCADView.obj : error LNK2001: unresolved external symbol "class CCommand * m_pCmd" (?m_pCmd@@3PAVCCommand@@A)
Debug/MyCAD.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

经检查,错误出现在全局变量的处理上。在视图类头文件中声明的全局变量要在视图类的实现文件中进行初始化:
// MyCADView.h : interface of the CMyCADView class
......
//声明全局变量
extern class CCommand* m_pCmd;
......

// MyCADView.cpp : implementation of the CMyCADView class
......
//声明的extern变量必须先赋值
CCommand* m_pCmd=NULL;
......

但为什么要这样处理,有没有其它处理办法,请高手指点。
 

回复:unresolved external symbol "class CCommand * ...

嘿嘿,这个只能去问微软了
 
1  /  1  页   1 跳转

版权所有 程序员家园论坛   Sitemap

Powered by Discuz!NT 2.1.202    Copyright © 2001-2008 Comsenz Inc.
Processed in 0.015625 second(s) , 4 queries. 浙ICP备07502118号
返顶部