C++笔试题
来源:互联网 发布:3d max mac中文版下载 编辑:程序博客网 时间:2024/04/29 07:49
请解释 aaa.h 中下面代码的功能
#if !defined(AFX_MYSUDU_H__9B952BEA_A051_4026_B4E5_0598A39D2DA4__INCLUDED_)
#define AFX_MYSUDU_H__9B952BEA_A051_4026_B4E5_0598A39D2DA4__INCLUDED_
... ...
#endif
预处理命令,可以保证多次包含此头文件时,只编译一次代码。
CMemoryState 主要功能是什么
用于检测内存泄露。
请解释下面代码采用了何种 C++ 特性( C 语言不具备),作用是什么?
template<typename T>
T sum(T a, T b)
{
return (a + b);
}
函数模板,用于将一类功能相同,参数类型和返回值不同的函数抽象为一个模板,方便模板函数调用。
请问下述代码中 : int operator+(… )起什么作用? this 是什么? ccc 的值最终为多少?
class Fruit
{
public:
Fruit()
{
weight = 2;
}
Fruit(int w)
{
weight = w;
}
int operator+(Fruit f)
{
return this->weight * f.weight;
}
private:
int weight;
};
Fruit aaa;
Fruit bbb(4);
int ccc = aaa + bbb;
int operator+(… )表示重载类的“+”号运算符,this表示对象本身的指针,本例中它指向类的对象aaa;ccc最终的结果为8(8 = 2 * 4)。
把下述代码加上异常处理。
int MyWriteFile(CString strFileName, CString strText)
{
int nRet = 0;
CFile myFile;
myFile.Open(strFileName, CFile::modeWrite|CFile::shareExclusive|CFile::modeCreate, NULL);
int nLen = strText.GetLength();
myFile.Write((char*)(LPCSTR)strText, nLen);
myFile.Close();
return nRet;
}
int MyWriteFile(CString strFileName, CString strText)
{
int nRet = 0;
CFile myFile;
__try
{
nRet = myFile.Open(strFileName,\
CFile::modeWrite|CFile::shareExclusive|CFile::modeCreate, NULL);
if(!nRet)
{
/// 输出异常信息
__leave;/// 结束try块,跳到__finaly代码块
}
int nLen = strText.GetLength();
nRet = myFile.Write((char*)(LPCSTR)strText, nLen);
if(!nRet)
{
/// 输出异常信息
__leave;/// 结束try块,跳到__finaly代码块
}
}
__finaly
{
myFile.Close();
}
return nRet;
}
- c++/c笔试题
- c/c++笔试题
- c笔试题
- C语言笔试题
- C语言笔试题
- C/C++笔试题!!!!
- C语言笔试题
- c笔试题
- c笔试题
- c语言笔试题
- c/c++笔试题
- 若干C笔试题
- C/C++笔试题
- c语言笔试题
- 一道C笔试题
- C/C++笔试题
- c/c++笔试题
- C/C++笔试题
- Android - 深入理解 JNI
- 图片正(逆)旋转90度java小程序
- ubuntu下安装samba
- Excel中实现隔行删除
- widget中使用动画效果
- C++笔试题
- CSS命名规范和CSS书写规范
- java连接mySQL数据库
- TOAD中查看执行计划(Explain Plan)
- 如何用SplitViewController控件
- 电子病历系统功能规范(试行)
- 汽车诊断简介
- java的读取方式
- 阿里软件资深架构师李战谈:开发者的人品问题