1. 程式人生 > >類:兩個練習題

類:兩個練習題

class A
{public:
  unsigned short a;
  unsigned short b;
  void f()
  { std::cout<<
    std::hex<<//十六
    a<<","<< b;}
};
class B
{public:
  unsigned int b;
  B(int bb):b(bb){}
  void f()
  {std::cout<<
   std::hex<< b;}
};
void main()
{
  B b(0x12345678);
  A* pa = (A*)&b;
  pa->f();//輸出什麼?
}






//有沒有錯?如果有該如何修改
class A
{
  int a;
  int* p;//
public:
  A()
  {
    p = new int[10];
    for(int i = 0;i<10;++i)
      p[i] = rand() % 100;
  }
  ~A()
  {
    delete [] p;
  }
};
void main()
{
   //功能:把p陣列中的資料拷貝到arr
   A a;
   int arr[10];
   memcpy(arr, ??, sizeof(int)*10);
}