Difference between object and instance: C ++

I followed several posts on SO, and finally, I can conclude that when we have something like:

Person name;

nameis an object of a class person.

It becomes an instance when it is created:

name=new Person();

I am starting in C ++, and so far I have seen that we can access functions and variables like:

Person name;
name.getValue;
name.callFunction();

We do not need to use an operator for this new. So, is it possible to say that the differentiating factor between an object and an instance can be ignored in C ++?

+4
source share
5 answers

In C ++, "object" and "instance" are used almost interchangeably.

class instance. class instance class.

++, class struct, , , instance class, , instance ( ).

virtual , -, : . virtual. , : ++.

class struct, (, Foo f;), (, some_function( Foo(17,22) )), (, new Foo(17, 22)) placement- new ( std::vector std::make_shared).

, class - instance ++ - class template - class. class template - class, - . template , "" class es. class template , ( " " ). (, - - ).

++ 1y lite, , ++.

int x = 0;
int& foo = x;
int* bar = &x;

x int.

foo int&, foo , , ! - - ( x).

bar int, int*, , , .

: , . -, , .

" ", , class es. ? , : .

3.9 [] ++. :

(1.8), (8.3.2) (8.3.5)

- (, cv-) , , , void.

"" , , "" . , "" : , , ( - , ).

, , , .

class template template s. 14.7 - " ", (a template) - .

+7

- .

+4

-, , "" "". . ++ , int double "objects". ++ , (, ) , . , ++ "", "".

, . , , , , .

Person - . name ( ) .

++ :

Person name;

: " " " ".

new Person() . , new , Java, ++ . , Person, , . : . Person :

Person*

, Person* Person . ( , :))

:

Person name = new Person();

; . :

Person* name_ptr = new Person();

Person :

name_ptr->getValue();
name_ptr->callFunction();

, , :

delete name_ptr;

, . , , , , .

, ++. , .

+4

"" "" . ++ . "" , " X", .

Foo f;

f. Foo. , f Foo.

. , , - .

Person name;

name Person.

Person* name = new Person();

name Person* ( Person). Person, new Person(). , name .

+2

,

: ? , , - ... , java ++

example: Object   std = new Student();

- , std - , std help new keyWord , , std Object

, .

example: Student std;

- , std - ( ), , .

:)

+2
source

Source: https://habr.com/ru/post/1530290/


All Articles