I am trying to send some variable into a public class member.
I have 3 variables say x, y ,z.
I want to have them as a class' member. Then i will restore them at a list.
class sınıf{
publicfloat num1 ;
float num2 ;
float num3;
};
..
void main(){
vector<sınıf<list;
cin>> x;
cin>> y;
cin>>z;
sınıf1= new sınıf;
//here i think i need some lines sending x y and z to num1 num 2 and num 3;
list.push_back(*sınıf1);
}
For example assume i got lots of classes sınıf1s and in a for while i send them to the list. I want exactly 14.class y variable and make some calculations with this variabe. how will i have it?
sınıf is a class. sınıf1 is an object. When you pass an object to push_back a copy of the object is made that will be stored in the vector. The objects stored in the vector doesn't have variable names (you cannot use name sınıf1 to access them). There are a few different ways to access the objects stored in a vector but one of the most common is to use an index to access the objects the same way you do with arrays. list[0] will access the first element, list[1] the second and so on. You can get the number of elements in the vector by using the size member function: list.size()