answersLogoWhite

0


Best Answer

There is no such thing as an anonymous object in C++ (no such term is defined by the standard). You can have anonymous classes, anonymous unions or unnamed objects, but never anonymous objects.

Consider the following:

int* p = new int();

This creates two variables: a pointer variable on the stack (named p) and an integer variable on the heap (unnamed). Although the int on the heap has no name of its own, it is identified by dereferencing the address stored in p (*p), so it is not strictly anonymous.

struct foo {

//...

foo operator++(int);

};

In the above example, the int parameter is unnamed, but since it is never referenced (because it is not used) it is not strictly anonymous.

You might consider the following an anonymous object:

class foo{};

void bar(foo& f){}

int main() {

bar( foo() );

}

The instance of foo in main is merely unnamed. When passed to bar, it is identified by the f reference, so it cannot be regarded as an anonymous object. Upon returning from bar, the unnamed instance falls from scope. At best this can be described as a temporary unnamed object, but not an anonymous object.

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is anonymous objects in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are the objects used in dev c plus plus?

Objects in Dev C++ are the same as objects in generic C++, insofar as an object is an instance of a class.


What do you mean by read only objects in c plus plus?

Objects that are not supposed to be written. Surprised?


What is the difference between active and passive objects in c plus plus?

Passive objects encapsulate state and operations, whereas active objects also encapsulate a process. Standard C++ does not support active objects.


Instantiation of objects in c plus plus?

Objects are instantiated when statically declared or dynamically created with the new keyword.


What is anonymous object in java?

Objects without their declarations known as Anonymous Objects. these are known as use & throw objects because these are died after one time use.


In c plus plus what are the three ways that classes can relate to each other?

Class wrappers (embedded objects), inheritance (derived objects) and friend classes.


What are entities in c plus plus?

Entities are the objects instantiated by your program, both at compile time and at runtime. Some objects are primitive data types, others are more complex such as objects instantiated from a class.


How do you write classes and objects for hospital management software using objective c or c plus plus?

You declare a class as follows: class MyClass { //some stuff here... } You create an object as follows: MyClass object; This is how you create classes and objects in C++.


What do you mean by initialisation of objects in c plus plus?

Initialization of objects means to provide an initial value for the object. This is usually done by the constructor, or it can be done with an assignment statement.


What is the term that describes the hiding of implementation details of objects from each other in a C plus plus class?

Encapsulation.


How c plus plus objects are allocated memory?

With the new operator.myclass myclasspointer = new myclass;...use the classdelete myclasspointer;


Casting in c plus plus?

Yes, you can cast in C++, both statically and dynamically. Objects can also be cast provided the class designer implemented the appropriate conversion operators.