Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Some sentences in qt can't be understood, and there is a pointer problem; Seek an explanation ~ ~
Some sentences in qt can't be understood, and there is a pointer problem; Seek an explanation ~ ~
1、A * c; A is a custom class. Is pointer C of type A* defined here?

Here represents an object pointer that defines class a.

2、d = c->m(); M is a defined function. What does this sentence mean? Execute (c->; M ()) and assign the value to d? c->; What exactly does m () mean? He is equivalent to C.M. Don't know much about arrow operators? ...

Because c is an object pointer of class a (actually an object), c can->; m(); Where m () should be a member function of class A, and if it is, it means calling the function! c->; M () is not equal to c.m, but equal to (*c). m()。

As for d = c-& gt;; m(); It should be an assignment statement, because I haven't read your source program, so I can't give you specific meaning.

3、c = new A(tr("/dev/video 0 "); Is a defined class. What does this sentence mean?

Because C is the object pointer of A, C = Newa (tr ("/dev/video0"); It means to dynamically allocate a memory to C to store Class A data, and initialize it with tr("/dev/video0 ").

Storage space application

New has three formats.

1, new data type;

2. New data type (initialization value);

3. New data type [constant expression];

For example:

int * p = new int

Float * p = new float;

Student * p = freshman; //Student is a student class.

* p = 4; //accessing the requested memory space through a pointer is also equal to int * p = newint (4);

Cout & lt& lt* p<& ltendl///and then output 4.

There is char * str = newchar [100]; //Apply for an array of 100 character space, and assign the first address to the character pointer.

Finally, pay attention to release the memory delete [] str;

It can be seen from your question that you are not good at applying for "classes and objects", "pointers and arrays" and dynamic memory space. If you continue, you must find relevant materials to study hard, otherwise the future courses will be difficult to learn!