I am a little bit swimming right now.
I try to get names and ages of my contacts.
I creates a structure for these informations, and would like to put them in a vector. However, the constructor for this one that contains: names, ages, and size of the vector isn't obvious right now !!! here is where I got to till now :
CPP file for the functions ---> ItVect.cpp
numElements represent the number of contacts that are in the vector
Capacity represents the size of the vector.(considering that it will get bigger after adding more contacts)
For the syntax info{string name="Empty"; int age=0}
Ito represents my structure, and the rest is the informations in my structure :
(This could represents my vector of structure . That s what i want to do)
_____________________________________________________________
|name1, age1 |name2, age2 |name3, age3 |....... ..|name n, age n
|___________|___________|___________|______|__________________
numElements represent the number of contacts that are in the vector
Capacity represents the size of the vector.(considering that it will get bigger after adding more contacts)
So you need to create your own vector? You might want to PM me.
For the syntax info{string name="Empty"; int age=0}
Ito represents my structure, and the rest is the informations in my structure :
Where in the C++ Standard is this syntax described?
The other part was ok:
numElements: how many contactInfo objects are stored in the Vector
capacity: how many contactInfo objects can be stored in the Vector
The capacity is an implementation detail. It allows certain optimizations. An icing on a cake, but currently ...
Your current Vector can be created as empty, or as large enough to store initializer data. There seems to be no way to access the elements, nor to change numElements, so capacity is moot for the moment.
class Foo {
T * array = nullptr;
size_t size = 0;
public:
Foo() = default;
Foo( T * data, size_t count )
: array( new T [count] ), size( count )
{
for ( size_t x = 0 ; x < size; ++x ) array[x] = data[x];
}
// Some of these must be written too:
// copy constructor
// copy assignment
// move constructor
// move assignment
// destructor
};
int main() {
T something[] = /* initializer*/;
auto N = sizeof(something) / sizeof(T);
Foo bar( something, N );
return 0;
}