Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is exactly an object in C++?

Tags:

c++

object

In the beginning of my journey learning C++, I thought an object is an OOP-only related term. However, the more I learn and the more I read, I can see that this not the case, and I can find that the term "object" has a more generalized meaning. I read a lot of materials on the net, but I could not yet find something clear/solid. May be I could not get to the correct place. I could get the standards and it has good paragraphs about this, but as you may know standard language is a bit difficult. and the information usually too scattered.

My question: would you please show me in a simple English What is an object in C++ outside the OOP world?

like image 646
Kamal Zidan Avatar asked May 12 '17 21:05

Kamal Zidan


People also ask

What is an object in C programming language?

The variable or instances of a class is called object in c. A class may contain several data items and functions. Thus, the object of a class consists of both the data members and the member functions of the class. The combining of both the data and the functions into one unit is called data encapsulation.

How to define a class and declare objects in C++?

Defining Class and Declaring Objects. A class is defined in C++ using keyword class followed by the name of class. The body of class is defined inside the curly brackets and terminated by a semicolon at the end. Declaring Objects: When a class is defined, only the specification for the object is defined; no memory or storage is allocated.

What are objects and classes in C sharp?

What are objects in C#? Csharp Programming Server Side Programming. Like any other object-oriented language, C# also has object and classes. Objects are real-world entities and instance of a class. Access the members of the class using an object. To access the class members, you need to use the dot (.) operator after the object name.

What are the characteristics of Objective C class?

Objective-C Characteristic The class is defined in two different sections namely @interface and @implementation. Almost everything is in form of objects. Objects receive messages and objects are often referred as receivers. Objects contain instance variables. Objects and instance variables have scope. Classes hide an object's implementation.


1 Answers

Short answer

From https://timsong-cpp.github.io/cppwp/n3337/intro.object

An object is a region of storage.


A slightly longer answer

In traditional OOP and OOD, an Object is used to describe class of objects some times and to an instance of a class some times.

In C++, class and struct represent classes.

An object in C++ can be an instance of a class or a struct but it can also be an instance of a fundamental type.

A few simple examples:

int i;

i is an object. It is associated with a region of storage that can be used by the program.

struct foo { int a; int b;};
foo f;

f is an also object. It is also associated with a region of storage that can be used by the program.

int* ptr = new int[200];

ptr is a pointer that points to 200 objects of type int. Those objects are also associated with a region of storage that can be used by the program.

like image 200
R Sahu Avatar answered Sep 28 '22 07:09

R Sahu