I was wondering if somebody could supply an example of a object. I can't seem to grasp the method of creating and initiating variables in an object either.
First define a class for your object. Every object is of a given class (or type). Give the class a constructor. Then you can define an object of that type giving it initial values:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
class Coordinate
{
double x, y;
// This is the constructor, it is called whenever you create
// an object of this class
Coordinate(double in_x, double in_y)
: x(in_x), y(in_y) // initialise object data
{
}
};
// create an object of type Coordinate
Coordinate x(2.7, 9.3);
// x is an object of type Coordinate initialised with 2.7 and 9.3
No. An object is the instantiation of a class/struct/union, not the class/struct/union itself. The c/s/u is more like a blue print for what the object looks like. Follow the above link ^