1
4

2 回答 2

1

Agree - works for me (g++ 4.6.1 on linux)

#include <stdlib.h>
#include <iostream>
#include <vector>

using namespace std;

struct B
{
  std::vector<std::vector<double> > c;
  void cpyV(const std::vector<std::vector<double> > &v)
  {
    c = v;
    return;
  }
} A;

int main(void)
{
 vector<vector<double> > a, b;
 vector<double> x;

 x.push_back(1.0);
 x.push_back(2.0);
 x.push_back(3.0);

 a.push_back(x);
 a.push_back(x);
 a.push_back(x);

 b = a;

 cout << "a:\n";
 for(unsigned i=0; i<a.size(); i++)
    {
     for(unsigned j=0; j<a[i].size(); j++)
        cout << a[i][j] << "\t";
     cout << "\n";
    }

 cout << "\nb:\n";
 for(unsigned i=0; i<b.size(); i++)
    {
     for(unsigned j=0; j<b[i].size(); j++)
        cout << b[i][j] << "\t";
     cout << "\n";
    }

 A.cpyV(a);

 cout << "\nA.c:\n";
 for(unsigned i=0; i<A.c.size(); i++)
    {
     for(unsigned j=0; j<A.c[i].size(); j++)
        cout << A.c[i][j] << "\t";
     cout << "\n";
    }


 return 0;
}

Produces the following:

a:
1       2       3
1       2       3
1       2       3

b:
1       2       3
1       2       3
1       2       3

A.c:
1       2       3
1       2       3
1       2       3
于 2013-11-13T18:14:59.183 回答
0

It looks like a compiler's library bug. You can also try the following code

c.assign( v.begin(), v.end() );
于 2013-11-13T17:59:48.597 回答