• Register
Log In

This article is more of an answer to a question given to me. The question is “is class a reserved word and it defines only a data type?” I’ll try my best to give all the things I know.


Is class a reserved word?

Yes, a class is a reserved word in C++. Class is a keyword i.e., it possesses a special meaning to the program.


Is the class defined only as a data type?

Yes, a class is defined as a data type. Class is a user-defined data type in C++

A class represents a group of similar objects. A class is a way to bind the data describing an entity and its associated functions together. For instance, consider an account having characteristics like account number, type, and balance. Its associated operations are deposit and withdrawal.

So we can define the class as:

class Account { int accountno;
                char type;
                float balance;
                float deposit(float amount)
                { balance+=amount;
                  return balance;
                float withdraw (float amount)
                { balance-=amount;
                  return balance;

See the data describing an account and its associated operations are bound together under one name Account. Thus Account makes a class. Now instances of the class Account can be created.

Need for classes

Classes are needed to represent real-world entities that not only have data type properties but also have associated operations.

posted May 26 in c++ 100 points