C++ Struct

//指出下面程序的问题
/*typedef struct TagStu
{
  int n;
}Stu;
void test(Stu* s[])
{
  cout<<s->n<<endl;
  cout<<(++s)->narrow<<endl;
}
int main()
{
  Stu* sTmp;
  sTmp = new Stu[10];
  test(sTmp); //传递的实参为指针,而test函数形参为Stu指针类型的数组,
  delete [] sTmp;
  return 0;
}*/

//修改为
typedef struct TagStu
{
  int n;
}Stu;
void test(Stu* s,int len)
{
  cout<<s->n<<endl;
  cout<<(++s)->n<<endl;
}
int main()
{
  Stu* sTmp;
  sTmp = new Stu[10];
  test(sTmp,10);
  delete [] sTmp;
  return 0;
}

posted @ 2015-10-16 14:47  fenghuan  阅读(367)  评论(0编辑  收藏  举报