科大讯飞 笔试面试问题
笔试编程题:
1.递归判断一个数组是否递增
2.循环左移字符串,最快的方法,不申请内存空间。(求最快的方法)如:abcde,左移两位cdeab
面试题:(经理问的)
1.拷贝构造函数,参数为啥是引用(知道),不能为指针吗(不知道)
2.两个类除了继承之外还有啥关系。(友元也不算,求解)
面试题1:
#include<iostream>
using namespace std;
class CExample
{
private:
int m_nTest;
public:
CExample(int x) : m_nTest(x) //带参数构造函数
{
cout << "constructor with argument" << m_nTest << endl;
}
// 拷贝构造函数,参数中的const不是严格必须的,但引用符号是必须的
explicit CExample(const CExample & ex) //拷贝构造函数
{
m_nTest = ex.m_nTest;
cout << "copy constructor" << endl;
}
CExample(const CExample* c_class)
{
m_nTest = c_class->m_nTest+2;
cout << "copy pointer constructor " << m_nTest<< endl;
}
CExample& operator = (const CExample &ex) //赋值函数(赋值运算符重载)
{
m_nTest = ex.m_nTest; cout << "assignment operator " << m_nTest << endl;
return *this;
}
};
int main(void)
{
CExample aaa(2);
CExample *bbb=new CExample(3);
CExample ddd(bbb);
system("pause");
} 
最后,“拷贝构造函数需要传入的是一个对象,如果拷贝构造函数的参数是指针的话,这个参数就是地址而不是对象了(仅仅指向对象而已)。所以不能用指针,不过指针和引用的传惨机制是一样的,指针对指向的对象而言不是传值得对自己而言是传值的
”(源自下的评论:http://blog.csdn.net/hackbuteer1/article/details/6545882)