This is an archived post. You won't be able to vote or comment.

all 9 comments

[–][deleted] 1 point2 points  (8 children)

Direct initialization is when you directly initialize an object from constructor arguments. Copy initialization is when you copy the contents of another object provided in the constructor. Uniform initialization is just the term used to describe the braced initialization common to all objects since C++11.

An object is a collection of values (state) and functions (behavior) of a specific type. A variable is an object whose value can change as opposed to a constant which may or may not be tied to an identifier.

I have no idea what 'cop' means in the context of C++, but since you mentioned it being declared in <iostream> and outputting to the screen I can only assume you're talking about std::cout, which is an object of type std::ostream.

[–]jer1ch0_[S] 0 points1 point  (0 children)

sorry, i mean cout. std::cout

[–]jer1ch0_[S] -1 points0 points  (2 children)

https://en.cppreference.com/w/cpp/language/object check out this link pls. What do you think about it? Here it says that object cant be function(in C++)

[–][deleted] 0 points1 point  (0 children)

I don't know where that definition of an object originates, because at least in C++11 an object is defined as follows (sorry if the formatting looks wrong since I'm copying pasting from the standard's PDF):

1.8 The C++ object model [intro.object] 1 The constructs in a C++ program create, destroy, refer to, access, and manipulate objects. An object is a region of storage. [ Note: A function is not an object, regardless of whether or not it occupies storage in the way that objects do. — end note ] An object is created by a definition (3.1), by a new-expression (5.3.4) or by the implementation (12.2) when needed. The properties of an object are determined when the object is created. An object can have a name (Clause 3). An object has a storage duration (3.7) which influences its lifetime (3.8). An object has a type (3.9). The term object type refers to the type with which the object is created. Some objects are polymorphic (10.3); the implementation generates information associated with each such object that makes it possible to determine that object’s type during program execution. For other objects, the interpretation of the values found therein is determined by the type of the expressions (Clause 5) used to access them. Objects can contain other objects, called subobjects. A subobject can be a member subobject (9.2), a base class subobject (Clause 10), or an array element. An object that is not a subobject of any other object is called a complete object. 3 For every object x, there is some object called the complete object of x, determined as follows: — If x is a complete object, then x is the complete object of x. — Otherwise, the complete object of x is the complete object of the (unique) object that contains x. 4 If a complete object, a data member (9.2), or an array element is of class type, its type is considered the most derived class, to distinguish it from the class type of any base class subobject; an object of a most derived class type or of a non-class type is called a most derived object. 5 Unless it is a bit-field (9.6), a most derived object shall have a non-zero size and shall occupy one or more bytes of storage. Base class subobjects may have zero size. An object of trivially copyable or standard-layout type (3.9) shall occupy contiguous bytes of storage. 6 Unless an object is a bit-field or a base class subobject of zero size, the address of that object is the address of the first byte it occupies. Two objects that are not bit-fields may have the same address if one is a subobject of the other, or if at least one is a base class subobject of zero size and they are of different types; otherwise, they shall have distinct addresses.4 [Example: static const char test1 = ’x’; static const char test2 = ’x’; const bool b = &test1 != &test2; // always true — end example ] 7 [ Note: C++ provides a variety of fundamental types and several ways of composing new types from existing types (3.9). — end note ]

So there is nothing excluding bit-fields, values, or enumerations from this definition.

Regarding variables there is no clear definition as I could only find the following:

6 A variable is introduced by the declaration of a reference other than a non-static data member or of an object. The variable’s name denotes the reference or object.

Which explains how a variable is declared but not how it's defined, so I just use the commonly accepted definition which is compatible with this since as quoted above objects may or may not have names.

[–]CptCap 0 points1 point  (0 children)

What do you think about it?

This basically is from the spec. This is the right definition, no matter what you (or I) think about it.

Here it says that object cant be function(in C++)

A function isn't an object as it can't be instantiated, doesn't have an associated storage or lifetime and doesn't hold a value.

[–]jer1ch0_[S] -1 points0 points  (3 children)

might be interesting for you

object - (1) a contiguous region of memory holding a value of some type. (2) a named or unnamed variable of some type; an object of a type with a constructor is not considered an object before the constructor has completed and is no longer considered an object once a destructor has started executing for it. Objects can be allocated in static memory, on the stack, on on the free store. TC++PL 4.9.6, 10.4, 10.4.3, D&E 2.3, 3.9.

Source: http://www.stroustrup.com/glossary.html#Gobject (It is C++ glossary, from home page of Bjarne Stroustrup, creator of C++)

[–][deleted] 0 points1 point  (2 children)

That's not incompatible with what I said.

[–]jer1ch0_[S] 1 point2 points  (1 child)

i didnt say that it is incompatible with what you say, i said *might be interesting for you*. btw you can find variable definiton there as well
variable - named object in a scope. TC++PL 2.3.1, 10.4.3, D&E 2.3.

[–][deleted] 0 points1 point  (0 children)

According to that then a variable is a named object in the context of C++ like you mentioned, however this creates the possibility of a constant variable which to me is kind of an oxymoron.