![]() |
In C++, when we declare a member as static, then it means that the member will have only one copy that is shared by all objects of that class and we don’t need any object to access that member In this article, we will learn how to declare a static data member in a class in C++. Declaring Static Data Member in a Class in C++To declare a static member within a class we can use the static keyword in the definition while defining a static member inside a class. Syntax to Declare Static Member in C++//inside class
static dataType dataMemberName;
Static data members must be initialized outside the class definition. C++ Program to Declare a Static Member in a ClassThe below example demonstrates how we can declare and access the static members in a class in C++. C++
Output
Value of static variable: 10
|
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |