首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 计算机考试 > 等级考试 > 复习指导 >

C++实用技巧三

2008-12-06 
prefix,surfix操作符重载;VS2005的C++/MFC工程部署问题

    1.prefix,surfix操作符重载

    C++标准规定:当为一个类型重载++, --的前置版本时,不需要参数;当为一个类型重载++, --的后置版本时,需要一个int类型的参数作为标志。
  可参考<The design and Evolution of C++>
  class Integer{
  long m_data;
  public:
  Integer(long data): m_data(data){}
  Integer& operator++(){
  cout << "Integer::operator++() called" << endl;
  m_data++;
  return *this;
  }
  Interger operator++(int){
  cout << "Integer::operator++(int) called" << endl;
  Integer tmp = *this;
  m_data++;
  return tmp;
  }
  };

    2.VS2005的C++/MFC工程部署问题

    VS2005的C++/MFC工程,在开发机上一切正常,换了机器(未安装VS2005)之后运行。弹出下列错误:
  由于应用程序配置不正确,程序未能启动,重新安装应用程序可能会纠正这个问题
  在Eventlog中有:Generate Activation Context ……参照的汇编没有安装在系统上
  原因:缺少应用程序运行所必须的C 运行库,标准 C++ 库和MFC类库,VS2003的应用程序在遇到同样
  问题的时候会直接在Error Message上说明所需的DLL,比如msvcr71.dll,msvcp71.dll,MFC71.dll。
  解决方法:
  总共有3种方法:
  1.静态链接DLL
  增加应用程序文件的大小并使得维护有可能更难进行,考试.大不推荐使用。
  如果你非要用的话,可以看文章最后的参考。
  2.将 Visual C++ 库 DLL 部署为共享程序集
  把Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\vcredist_x86\vcredist_x86.exe
  拷贝到其他机器上运行即可。
  注意:(1)对于将 64 位应用程序部署到 64 位操行系统,使用 vcredist_x64.exe 或 vcredist_ia64.exe。
  (2)此方法仅应用于Release版。
  (3)务必保持编译程序的VS版本同vcredist_x86.exe的版本一致。比如VS为8.0.50727.762,
  那么vcredist_x86.exe的版本就应该是2.0.50727.762
  3.将 Visual C++ 库 DLL 部署为私有程序集
  把Microsoft Visual Studio 8\VC\redist\x86的Microsoft.VC80.CRT和Microsoft.VC80.MFC文件夹下的
  全部文件拷贝到目标机器的和Exe同一目录下。
  注意:(1)对于将 64 位应用程序部署到 64 位操作系统,使用 \vc\redist\amd64 或 \vc\redist\ia64。
  (2)对于调试应用程序,使用 \vc\redist\debug_nonredist\ 中的 DLL。
  详细可以参考:
  http://msdn2.microsoft.com/zh-cn/library/ms235291(VS.80).aspx

 

3COME考试频道为您精心整理,希望对您有所帮助,更多信息在http://www.reader8.com/exam/

热点排行