Little knowledge Miscellany

1.QString and local std :: string conversion between

 

std::string s=qstr.toStdString();
QString qstr=QString::fromStdString(s);

 

In 2.Qt encountered error: LNK2019: unresolved external symbol

It may be because before then compile error correction code does not cover the generation .obj files (guess). The debug / release folders deleted, re-compile and run.

 3. The header file must not have realized.

Write header files must take the time to write in the corresponding realization .cpp source file, do not write in the header files, header files, only statements. So here is a question, why the generic header files can be written to achieve? First, the function body can not write a generic function in another file, generic programming is so specified, but the body of the function generic functions and should not really realize, because only when the call determines the type it is possible to achieve this function body functions, generic functions only to the compiler to tell it how to generate a template defined; then the header file containing the generic can .cpp source file? Obviously it can, for example, contain generic header file There are other non-generic function, or must implement these functions in the .cpp file.

 4. In the definition of the class file .cpp

We know that is defined in the corresponding .cpp .h file in an external class can not be used because other files that contain only the .h files can not be used in the corresponding .cpp defined class (either undefined identifier appears error message, or is not allowed to use an incomplete type errors - this is the pre-declared in the .h file the case), such a benefit is if you want to define classes only as a .h file that contains the main class support classes, which do not want to use external, can be defined in the corresponding .cpp file.

Const function is set to 5. It does not change the shape parameters const parameters, without changing the class member functions member variable

I think this is a good habit, not only shows the function does not change the parameter or member variable of intent, but also compatible with the const arguments.

6 * & * & and what it means

It is intuitive meaning, * represents dereference & address after the first take, & * denotes first take dereference address. After taking dereference address, after taking dereference address, or it is not their own, why many times in one fell swoop? In fact, not necessarily. Functions such as double * & p parameter indicates that the parameter is a pointer pointing to a double reference; another example std :: vector <double> :: iterator it = v.begin (); // v corresponding type vector, while another function void fun (double *), may be used fun (& * it), on the first iteration element dereferencing obtained, after taking the address pointer to be pointed element type, there has not been iterator * & itself because iterator * overloaded.

7. Save the pointer vector can be pressed into the empty NULL pointer it?

can. Just remember to determine whether NULL just fine before use.

Published 28 original articles · won praise 14 · views 20000 +

Guess you like

Origin blog.csdn.net/liyunxin_c_language/article/details/83188671