I am not sure if this is correct C++ code anyway, (so please correct me if not)
#include
#include
using namespace std;
struct TestStruct
{
string testStr[2][2];
/*
TestStruct &operator= (const TestStruct &src)
{
testStr[0][0] = src.testStr[0][0];
testStr[0][1] = src.testStr[0][1];
testStr[1][0] = src.testStr[1][0];
testStr[1][1] = src.testStr[1][1];
return *this;
}
*/
};
int main()
{
TestStruct a, b;
a.testStr[0][0] = "1234567890";
b = a;
printf("Done \n %s", b.testStr[0][0].c_str());
return 0;
}
With no assignment operator, the default generated one causes a "double free or
corruption" error. Single arrays work fine, but I am also unsure what the
correct C++ behaviour should be in this case.
--
Summary: Assignment operator broken with multidimensional array
strings.
Product: gcc
Version: 3.4.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: dtrebilco at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25735