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) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 突泉县| 三河市| 阿克苏市| 屏东市| 栾川县| 清徐县| 淮滨县| 施甸县| 宜兰市| 伊通| 新巴尔虎左旗| 青铜峡市| 临湘市| 黑水县| 那坡县| 武城县| 政和县| 土默特左旗| 云林县| 弥勒县| 得荣县| 大理市| 缙云县| 阿拉善右旗| 平谷区| 江津市| 伊通| 肥城市| 顺平县| 肥东县| 衢州市| 临洮县| 康平县| 天全县| 新乐市| 勃利县| 饶河县| 丰都县| 敦煌市| 宁波市| 宜丰县|