#include <iostream>
using namespace std;
struct td{
int ** subj_no;
};
int main(){
td p;
**p.subj_no = new int * [7];
}
If not then how should I accomplish this task? What's the corrected version?
#include <iostream>
using namespace std;
struct td{
int ** subj_no;
};
int main(){
td p;
**p.subj_no = new int * [7];
}
If not then how should I accomplish this task? What's the corrected version?
Close but not quite.
What sort of structure are you intending to create? If it's a two dimensional array, you first allocate the pointers to the rows, then allocate the rows, like:
int main(){
td p;
int i;
p.subj_no = new int * [7];
for( i = 0; i < 7; i++ )
p.subj_no[i] = new int [10]; //now we have 7 rows of 10 items
}
You could write a constructor method for your struct. Keep in mind that in C++ the only difference between a struct and a class is the default visibility.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.