Functions and Objects

Instantiation in C++

Used to create an object (class instance) from a class.


Syntax
className objectName(parameters);

Notes

Input requirements are taken from the constructor. A class can have multiple constructors with different numbers of input parameters and types, to create different objects.

An instance of a class is called an object.


Example
using namespace std;
//class looks like this
class Car {
public:
    string make;
    Car(string make) {
        this->make = make;
    }
}
 
//instantiation, elsewhere in the program
Car myCar("Honda"); //passing in Honda into the make variable

See Also
Documentation

Classes - C++ Tutorial

Add to Slack

< Constructor   |   Functions >

© 2019 SyntaxDB. All Rights Reserved.