J-XMoses

          J-XMoses

          typedef keyword in C++

          read this article -> http://www.functionx.com/cpp/keywords/typedef.htm
          It said that "The typedef keyword can be followed by an attribute before the data type. In its simplest form, the attribute can be that of an access level such as public, private, or protected." and provide a examples:


          #include <iostream>
          #include <string>
          using namespace std;
          
          typedef struct Student;
          typedef class Country;
          
          typedef public short SmallNumber;
          typedef private unsigned int Positive;
          typedef protected double* PDouble;
          typedef public string FiveStrings[5];
          typedef private double (*Addition)(double value1, double value2);
          
          struct Student
          {
          	string FirstName;
          	string LastName;
          };
          
          typedef struct _Empl
          {
          	string FullName;
          	double HourlySalary;
          }Employee;
          
          class Country
          {
          	string Name;
          	string Capital;
          	string Code;
          };
          
          double Add(double x, double y)
          {
          	double result = x + y;
          	return result;
          }
          
          typedef enum EmplStatus { esFullTime, esPartTime, esContractor };
          typedef Student *PStudent;
          typedef Country *PCountry;
          
          int main()
          {
          	Student pupil;
          	Country pais;
          	EmplStatus emplst;
          	PStudent ptrStd = new Student;
          	PCountry pPais = new Country;
          
          	return 0;
          }


          I found that I can't compile it on my Linux using g++.


          [root@sd1 xxx]# g++ typedef.cpp -o typedef
          typedef.cpp:8: error: expected unqualified-id before 'public'
          typedef.cpp:9: error: expected unqualified-id before 'private'
          typedef.cpp:10: error: expected unqualified-id before 'protected'
          typedef.cpp:11: error: expected unqualified-id before 'public'
          typedef.cpp:12: error: expected unqualified-id before 'private'


          Why, can anybody tell me?
          :)

          posted on 2007-03-22 17:48 Java-XMoses 閱讀(472) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 怀远县| 石林| 商洛市| 兴国县| 武山县| 台山市| 华宁县| 呈贡县| 尼勒克县| 聊城市| 揭东县| 宣威市| 武功县| 富宁县| 尼玛县| 武定县| 宜城市| 襄樊市| 宝应县| 新竹市| 宁明县| 温州市| 同德县| 台江县| 巴彦淖尔市| 车险| 沂源县| 瓮安县| 琼中| 德安县| 德江县| 西盟| 乌海市| 嘉善县| 习水县| 云南省| 洛川县| 大理市| 古浪县| 苍溪县| 西林县|