Array within a Class
Arrays can be used as data members in a class. an Array can be a private or a public data member of the class. If an array is a private data member of the class, then only the member functions of the class can access it. Otherwise if an array is a public data member of the class, it can be accessed directly using objects of the class type. Consider the following class definition:
class myarray
{
int a[20];
public;
void getval(void);
void display(void);
};
Here, the arrray a is declared as a as a private member of the class myarray. It can be accessed only through the member functions of the class like any other private data member . The member function getval() reads the values of elements of the array a and the member function display() prints the values of elements of the array a. LEARN MORE>>
Showing posts with label Scope. Show all posts
Showing posts with label Scope. Show all posts
Scope Rules in C++
Scope determines visibility of identifiers across function/procedure boundaries, code blocks and source files. The scope rules of a language decide in which part(s) of the program a particular piece of code or data item can be accessed.
There are five types of scopes in C++
Function
File
Block
Function Prototype
Class
LEARN MORE>>
There are five types of scopes in C++
Function
File
Block
Function Prototype
Class
LEARN MORE>>
Subscribe to:
Posts (Atom)