What does int * v[3] would do? I think it will create a vector of pointers but it doesn't let me add values to those pointers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What does int * v[3] would do? I think it will create a vector of pointers but it doesn't let me add values to those pointers

I'm using v[0]= 2; to add a value to them

30th Apr 2017, 4:33 PM
Josue Picado
Josue Picado - avatar
5 Answers
+ 2
at() method only for vector. Not for array. You have to create vector of Name class type to use it.
1st May 2017, 12:37 AM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 1
Well, for creating vector you have to write it like vector<int> v[3]; What you are writing will create three pointers in array. Also when adding or change value in vector use at() method. It will throw an error if there is no index.
30th Apr 2017, 4:45 PM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 1
int, string are structure not class. You have to define structure if you only want to store something in it. class are like structure with function and many other features. If you use it like you said, in your second post. You can add data to it like Name *obj[4]; obj[0] = new John(); obj[1] = new David(); obj[3] = new Daniel(); Where John, David and Daniel are Name class type object.
30th Apr 2017, 5:23 PM
Aditya kumar pandey
Aditya kumar pandey - avatar
0
In this case let's say I have a class called Name and I want to create an array with them so I used, Name * v[3], what am I creating in there? And how can I add values?
30th Apr 2017, 5:08 PM
Josue Picado
Josue Picado - avatar
0
Oh I get it, and if I use it with int, as you said on the first answer, how should I use the at()? I tried it but I gave me a compilation error
30th Apr 2017, 5:25 PM
Josue Picado
Josue Picado - avatar