I want to do something like the snippet below:
using namespace std;
struct str {
int *integs;
};
void allocator(str*& str1) {str1.integs=new int[2];}
void destructor(str*& str1) {delete [] str1.integs;}
int main () {
str str1;
allocator(str1);
str1.integs[0]=4;
destructor(str1);
return 0;
}
However this doesn’t work; I get error: request for member ‘integs’ in ‘str1’, which is of non-class type ‘str’*
Is this impossible to do with struct and I need a class? Do I have to use the -> operator somehow? Thoughts?
You’re taking
str1as a reference to a pointer. You probably meant: