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 閱讀(470) 評論(0)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 长乐市| 沙田区| 博罗县| 丘北县| 萨嘎县| 富阳市| 潼关县| 重庆市| 丰镇市| 兖州市| 昭苏县| 营口市| 双流县| 韩城市| 丹寨县| 房山区| 抚顺市| 泗水县| 上虞市| 安达市| 西吉县| 普格县| 黄山市| 辽宁省| 巢湖市| 额敏县| 浠水县| 崇义县| 晋城| 双峰县| 江山市| 贵州省| 栾城县| 鹤峰县| 桓仁| 舒兰市| 阳新县| 广元市| 类乌齐县| 彰化市| 安义县|