C++: Voiding a function

As was mentioned, a function could have a type such as int or string.

In the previous example, the SpeedCheck function was declared as an Integer type.  As you can see, this function only prints out a statement and we do not need it to return a value.

We can declare the function as void as shown in the example below.

In the class declaration, we need to specify that this is a void function as well.

#include <iostream>

using namespace std;

class Plane

	double speed;

	void SpeedCheck(double);

	Plane();  //This is the constructor
	~Plane();  //This is the destructor


void Plane::SpeedCheck(double sp)

	double speed = sp;

	if (speed >= 1000)
		cout << "You are going interstellar";
		cout << "You are doing just fine";




int main()

	double speed = 1001;

	Plane Plane1; // instance declaration
	cout << endl;


Series Navigation<< C++: Another example on creating an object
C++: Properties of an object >>