Why do I get this error:
test.cpp:11:28: error: no match for ‘operator=’ in ‘*(((Test*)this)->Test::a_list + ((unsigned int)(((unsigned int)i) * 20u))) = Test::foo2()’
When I compile the below code (via g++ test.cpp -o test
)
test.cpp:
#include "test.h"
Test::Test () {}
void Test::foo1 ()
{
int i;
a_list = ( A* ) malloc ( 10 * sizeof ( A ) );
for ( i = 0; i < 10; i++ )
a_list [ i ] = foo2 ();
}
}
A* Test::foo2 ()
{
A *a;
a = ( A* ) malloc ( sizeof ( A ) );
return a;
}
Test.h:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
typedef struct
{
double x;
double y;
string z;
} A;
class Test
{
public:
Test ();
void foo1 ();
private:
A* foo2 ();
A *a_list;
};