alex

different between C and C++ when initialize the structure

when initialize a sturcture, its different between c and c++.
for example:
struct Student
{
      int id;
      int age;
      char *name;
};

const int def_id = 999;
const int def_age = 18;

struct Student stud = 
   {
         def_id,
         def_age,
         "jackson"
   };

the code can not be compiled in c but can be compiled in c++.

Reason:
   In c, only constant value can be used to initialize a structure.
   but in c, only Micor and Enum is constant value.  const just means the value of the variable can not be changed , but the variable is not constant.

posted on 2007-01-30 10:39 alex 阅读(245) 评论(0)  编辑 收藏 引用 所属分类: Technique


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理