structs, like classes, can have member functions and custum operators associated with them. The line in question is a constructor for the 3D_Point struct object and tells how to build a 3D_Point object.
In particular, the constructor here takes three parameters x1, y1, and z1 that is used to initialize the struct members x, y, and z respectively. The argument list specifies default arguments, the = 0.0f parts, that are to be used if the caller declines to provide an argument. By using the default arguments here, the user has the option of specifying either 3, 2, 1 or none of the arguments when constructing a 3D_Point object, i.e.:
Code:
tankRoute2.push_back(3D_Point()); // Add pt 0.0, 0.0, 0.0 to the vector
tankRoute2.push_back(3D_Point(4.2)); // Add pt 4.2, 0.0, 0.0 to the vector
tankRoute2.push_back(3D_Point(4.2, 9.6)); // Add pt 4.2, 9.6, 0.0 to the vector
tankRoute2.push_back(3D_Point(4.2, 9.6, 8.1)); // Add pt 4.2, 9.6, 8.1 to the vector
The part after the : is called an initializer list and is basically just a shortcut for assigning the arguments to the member variables. It basically states "take the argument provided for x1 and assign it to x" and so on for each of the other two arguments. The two braces specify the body of the constructor which in this case is empty because we did our initialization using the initializer list. We don't have to use the initializer list, it could be removed from the constructor which could be rewritten as:
Code:
3D_Point( float x1 = 0.0f, float y1 = 0.0f, float z1 = 0.0f )
{
x = x1; // Do our assignment in body of constructor...
y = y1; // instead of in initializer list
z = z1;
}
As for the problem you are describing above, try to compile a minimal (and complete) program example using your struct and a vector in your environment to see if you still get that error. For example:
Code:
#include <vector>
struct points
{
float x, y, z;
points( float x1 = 0.0f, float y1 = 0.0f, float z1 = 0.0f ) : x(x1), y(y1), z(z1) {}
};
int main()
{
std::vector<points> tankRoute2;
tankRoute2.push_back(points(0.450897f, 0.066000f, 0.023682f));
tankRoute2.push_back(points(0.203909f, 0.086718f, 0.021484f));
tankRoute2.push_back(points(0.321878f, 0.463296f, 0.027344f));
tankRoute2.push_back(points(0.450897f, 0.066000f, 0.023682f));
return 0;
}
As a complete program, the above sample should compile without errors (unless I'm missing something). If it compiles for you as well then it is likely that there is something else in your code that is causing this error in which case it would help to see as much of your code as possible. Also, what compiler and OS are you using just for grins.