Hi! "OBJECT is an instance of a class" then where is the object in the following code please........

class A 
{
 int a;
 int b;

 public:
 
 void display()
{

 cout<<"where is the object?";

};

Recommended Answers

All 8 Replies

This is the java forum not c++

This is the java forum not c++

But anyway it's OOP...please try answer the question

But anyway it's OOP

that's a myth...

C++ is NOT an object-oriented programming language it is a language with direct, native support for multiple programming paradigms

that's a myth...

C++ is NOT an object-oriented programming language it is a language with direct, native support for multiple programming paradigms

Then okay. But we use objects in c++ and some standard books quote it as OO language.I mean to say can't we find OBJECTS in the class definition?That I have threaded..?

To still answer your question. Above code does not create an object of the given class. You can consider class as a template as to what your object will look like. Using this class you can create an object in some other function (where you wish to use it) . And the function where you create the object will then invoke display() method on that object.

Hi, i can say that: the objects are in the heaven! :D
'cause you had just described your class, you didn't declare any object!
Anyway, if you add this code:

A myA = new A();

then myA will be stored in memory, be processed ...and when you exit your program, myA will disappear!

myA won't disapear because it is allocated on the heap. you have to do delete myA; before your program exits then it will 'go away'

by the way this is the C++ forum, not the java one

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.