Yes, this will work.
About the refinement of this code:
Since you need adding element i from one structure to another, probably you may need any other operations over such element, so it looks sensible to define a struct for it, and a retrieving operator:
struct element
{
double f1, f2;
int f3;
}
element& structtype::operator [] (int i)
{
return {vec1[i], vec2[i], vec3[i]};
}
const element& structtype::operator [] (int i) const
{
return {vec1[i], vec2[i], vec3[i]};
}
After implementation of these operation you probably may store element somewhere else, not only in the structtype, which means that push_back operation with element argument would be useful:
void push_back(const element& e)
{
vec1.push_back(e.f1);
vec2.push_back(e.f2);
vec3.push_back(e.f3);
}
Also, given that the structtype class behaves like a container, it may be useful to implement some other features typical STL containers provide, like iterators. A good guide for STL-like containers implementation is here.
Or, as a second option, you may just use std::vector<element>, which already implements all of these features.
If its functionality is not enough for you, you may extend it creating a new class which inherites the implementation of std::vector. A standard way of doing it is using a private inheritance, like this:
class structtype : private std::vector<element>
{
public:
/// Write such lines for all members of std::vector which you would like to have
using std::vector<element>::size();
...
/// Write some your own methods
std::vector<double> get_vec1() const;
}