GCC4.7.0在官网。VS2010是绿色版。在如下地址:
http://www.cppblog.com/romangol/archive/2010/05/27/116479.aspx#163998程序比较简陋,测试用。
G++编译通过,VS2010未通过编译。报错如下:
D:\VS2010SP1\\include\vadefs.h(48) : error C2144: syntax error : missing ';' before type 'unsigned int'
D:\VS2010SP1\\include\vadefs.h(48) : fatal error C1004: unexpected end of file found
代码如下:
1 #include <iostream>
2 #include<vector>
3 using namespace std;
4
5 class base
6 {
7 public:
8 base(int ii):i(ii){}
9 int geti(){return i;}
10 private:
11 int i;
12 };
13 class derived:public base
14 {
15 public:
16 derived(int ii,int jj):base(ii),j(jj){}
17 int getj(){return j;}
18 private:
19 int j;
20 };
21
22 static vector<base> vecb;
23 static vector<derived> vecd;
24 inline void scin(void)
25 {
26 int i;
27 cout<<"请输入一个数字:"<<endl;
28
29 for(int j=0;j<3;j++)
30 {
31 cin>>i;
32 vecb.push_back(base(i));
33
34 }
35
36 };
37 inline void scin1(void)
38 {
39 int a,b;
40 cout<<"请输入一对数字:"<<endl;
41
42 for(int j=0;j<3;j++)
43 {
44 cin>>a>>b;
45 vecd.push_back(derived(a,b));
46 }
47
48 }
49 inline void freeitb(void)
50 {
51 for(int i=0;i<vecb.size();i++)
52 vecb.pop_back();
53 }
54 inline void freeitd(void)
55 {
56 for(int i=0;i<vecd.size();i++)
57 vecd.pop_back();
58 }
59 int main()
60 {
61
62 vector<base>::iterator itb;
63 vector<derived>::iterator itd;
64 scin();
65 for(itb=vecb.begin();itb!=vecb.end();itb++)
66 cout<<itb->geti()<<endl;
67 freeitb();
68
69 scin1();
70 for(itd=vecd.begin();itd!=vecd.end();itd++)
71 cout<<itd->geti()<<","<<itd->getj()<<endl;
72 freeitd();
73 cin.get();
74 return 0;
75 }
76
77