According to what I have found in this question an array of references is illegal. Im kinda new to C++ and was playing around with pointers and dereferencing and the following code seems to execute just fine.
#include <iostream>
#include <cstdlib>
using namespace std;
struct A
{
int data1;
int data2;
A (void) : data1(0), data2(0) {}
// many more datas
};
int main()
{
cout << "test start" << endl;
A *a = new A();
A arr[100];
for (int x=0; x<100; x++) arr[x] = *a;
cout << "test done" << endl;
}
what happens here under the hood? is a copy of the a
object being put in every location of the array
? if so, when returning a object reference from a function like:
A &function (void) { return &A(); }
is it the same thins as this?:
A function (void) {return A();}