c++---面试题
>虚函数继承后的内存模型https://home.cnblogs.com/u/feliz/
>虚函数表: https://blog.csdn.net/haoel/article/details/1948051
https://blog.csdn.net/haoel/article/details/3081328 https://blog.csdn.net/haoel/article/details/3081385
>面试题集锦: https://wenku.baidu.com/view/566b163887c24028915fc3f4.html
https://www.cnblogs.com/Y1Focus/p/6707121.html
1.多态类中的虚函数表是Compile-Time,还是Run-Time时建立的? 第1题:虚函数表是Compile-Time时建立的
34,在main函数执行之前,还会执行什么代码和工作
答:运行全局构造器,全局对象的构造函数会在main函数之前执行
设置栈指针,初始化static静态和global全局变量,即数据段的内容
将未初始化部分的赋初值:数值型short,int,long等为0,bool为FALSE,指针为NULL等
将main函数的参数,argc,argv等传递给main函数
48,main 主函数执行完毕后,是否可能会再执行一段代码,给出说明?
答:可以,可以用_onexit 注册一个函数,它会在main 之后执行int fn1(void), fn2(void), fn3(void), fn4 (void)
51,什么是函数模板 |泛型编程
答:函数模板技术定义了参数化的非成员函数,使得程序能够使用不同的参数类型调用相同的函数,而至于是何种类型,
则是由编译器确定从模板中生成相应类型的代码。编译器确定了模板函数的实际类型参数,称之为模板的实例化。
template<class T>定义模板标识
T Add(T a, T b) //函数模板
{
T result = a + b;
return a + b; //将两个参数使用“+”运算符进行运算,这两个参数并不知道是何种类型
}
该函数与一般函数的不同之处在于没有明确指出使用何种数据类型和返回值又是哪一种类型
如何在程序中调用该函数
#include<iostream> //包含标准输入输出头文件
#include<string> //C++中的字符串处理头文件
using namespace std;
template<class T>
T Add(T a, T b) //函数模板
{
T result = a + b;
return a + b; //将两个参数使用“+”运算符进行运算,这两个参数并不知道是何种类型
}
int main(int argc, char* argv[])
{
cout<<"2+3="<<Add(2,3)<<endl; //输出整形的+运算结果
cout<<"sdf+123="<<Add(string("sdf"), string("123"))<<endl;
return 0;
}
52,什么是类模板
答:描述了能够管理其他数据类型的通用数据类型,通常用于建立包含其他类型的容器类
对于这些容器,无论是哪一种数据类型,其操作方式是一样的,但是针对具体的类型又是专用的,
template<class T>
class TemplateSample
{
private:
T& emtity; //使用参数类型成员
public:
void F(T& arg); //使用参数类型定义成员函数
}
该示例定义了一个类模板,类模板中的模板形参T需要用户在使用的时候进行定义
TemplateSample<int>demo; //针对该模板使用int类型
demo.F(123); //调用类模板中的成员函数
template<class T1, class T2, int num> //定义多个模板参数,且其中一个直接使用int类型
该示例的前两个参数可以是任何类型,但是第三个参数一定是int类型
TemplateSample<int , char, 12>demo; //使用非类类型的模板
#include<iostream>
template<class T, class T2, int num>
class CSampleTemplate
{
private:
T t1;
T2 t2;
public:
CSampleTemplate(T arg1, T2 arg2) //构造函数中使用模板参数
{
t1 = arg1 + num;
t2 = arg2 + num;
}
void Write()
{
std::cout<<"t1:"<<t1<<"t2"<<t2<<endl;
}
CSampleTemplate ()
{}
}
int main(int argc, char* argv[])
{
CSampleTemplate<int, int, 3>temp(1,2);
temp.Write();
return 0;
}
http://c.biancheng.net/view/2318.html
Vector: https://www.cnblogs.com/aminxu/p/4686332.html
https://www.cnblogs.com/yjd_hycf_space/p/7495640.html
https://blog.csdn.net/ljh0302/article/details/81098764
https://www.jobui.com/mianshiti/it/cpp/5018/
https://www.cnblogs.com/Y1Focus/p/6707121.html
https://www.runoob.com/cplusplus/cpp-interfaces.html
http://c.biancheng.net/cplus/c2cpp/
C++其他考试题:
https://www.jobui.com/mianshiti/it/cpp/5014/
https://www.jobui.com/mianshiti/it/cpp/5015/
https://www.jobui.com/mianshiti/it/cpp/5016/
https://www.jobui.com/mianshiti/it/cpp/5017/
浙公网安备 33010602011771号