C++面试题,有空的来看看。
C/C++
1)
Write a class that implements a simple list. It must provide methods to add and remove values, and provide some way to iterate through all elements in the list.
2)
Write destructors for these two classes.
class A
{
public:
int *a;
A() { a = new int[10]; }
};
class B : public A
{
public:
int *b;
B() { b = new int[20]; }
};
3)
Given the following definition, write a constructor that sets the value of m_constant.
class CConstant {
public:
const int m_constant;
const int Get() {return m_constant; }
};
4)
Write a copy constructor for the Circle class defined below. In what two situations does the C++ compiler use the copy constructor implicitly?
class Circle {
public:
Circle();
int center_x;
inst center_y;
double r;
};
5)
What is a hash table? What is its purpose, and how does it function?
6)
What does mysteryFunction return?
int mysteryFunction ( int n)
{
int k = 0;
while( n ) {
k++; n = n / 10;
}
return k;
}