关于C++构造函数初始化的问题(跪求!!!)

来源:百度知道 编辑:UC知道 时间:2024/05/24 07:49:46
01 #include<iostream>
02 using namespace std;
03
04 class A{
05 int g[4][2];
06 public:
07 A(int x1[],int x2[],
08 int x3[],int x4[]):
09 g[0](x1),g[1](x2),g[2](x3),g[3](x4){}
10 void show() const{cout<<g[0]<<g[1]<<g[2]<<g[3];}
11 };
12
13 int main(){
14 int y[4][2]={{1,2},{3,4},{5,6},{7,8}};
15 A a(y[0],y[1],y[2],y[3]);
16 a.show();
17 y[2][1]=3;
18 a.show();
19 }

为什么编译到09行时会弹出“expected‘(’before‘[’token”?
这东西真是令我吐血了,调试了半天没结果,难道构造函数不能
这样给数组初始化?
我也查过很多关于C++的书也没找到答案,各位高手帮帮忙,本人在
此先谢谢了!

//vc6下编译通过
//修改:qmroom
//2008-11-01 20:18
//blog:http://blog.csdn.net/qmroom
//Email:qmroom#126.com        #=@

#include <iostream>
#include <iterator>
using namespace std; 

class A

    int g[4][2];
public: 
    A(int (*x)[2])
    {
        memcpy(g, x, sizeof(g)); //数组这样初始化
    }

    void show() const
    {
        copy(g[0], g[0]+8, ostream_iterator<int>(cout, " ")); //输出数组