Objects

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.

Thanks In Advance
An 'object' is a variable defined by a class, struct, or union whose members can be variables or functions.

http://www.cplusplus.com/doc/tutorial/classes/
Last edited on
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 
An 'object' is a class, struct, or union

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 ^
Sorry, I know that I just worded it wrong. I'll fix it.
Topic archived. No new replies allowed.