I am unclear about the following.
First, this code compiles fine:
#include
typedef struct{
int x1,x2,x3,x4;
} ints;
typedef std
error: ISO C++ forbids initialization in array new
error: array must be initialized with a brace-enclosed initializer
error: invalid array assignment
error: request for member ‘~int [4]’ in ‘* __p’, which is of non-class type ‘int [4]’
To understand one of the errors, imagine the following:
void main() {
int a[4] = {0,1,2,3};
int b[4] = a;
}
As opposed to:
typedef struct{
int x1,x2,x3,x4;
} ints;
int main()
{
ints a;
ints b = a;
}
Or even:
typedef struct{
int x[4];
} ints;
int main()
{
ints a;
ints b = a;
}
C/C++ arrays cannot be copied via the assignment operator, though struct
s containing arrays can be.
So an easy fix is to do:
typedef struct{
int x[4];
} ints;
typedef std::vector vec;
int main(){
vec v;
ints a = { {0,1,2,3} };
v.push_back(a);
}