It doesn’t seem to be a problem. By looking at http://www.cplusplus.com/forum/general/153830/ to find the reason of the error:
A temporary object can’t bind to A non-const reference.
(A temporary object cannot be bound to an extraordinary reference, that is, the bound reference must be constant)
Therefore, the parameter of the overloaded = function must be const. (Such a covert mistake is more than enough to cry about…)
Error1 disappears after adding const:
MyComplex& operator = (constMyComplex & rhs){
Real = RHS. GetReal ();
Imaginary = RHS. GetImaginary ();
Return * this;
}
Error2 has the same error cause.
Friend ostream& operator< < (ostream& os,const MyComplex & c);
Const is very important! Want to! !!! After the correction, the errors disappeared
Can the size of an array be defined at run time? no. In the definition of an array, the size of the array must be known at compile time, not at run time. For example, if I is a variable, you cannot use I to define the size of an array: char array[I]; Notvalidc */ supports this definition in some languages, but not in C. If C supported this definition, the stack would become more complex, the overhead of calling functions would be greater, and the program would run significantly slower. if the size of the array is known at compile time, even if it is a very complex expression, you can define it as long as it can be calculated at compile time. If you want to use an array whose size is not known until the program is running, you can specify a pointer and call the malloc() or calloc() functions to allocate memory space for the array from the heap. Here is an example of an argv array that is copied to the main() function:
[cpp]
view plain
copy
7.15 cases in row to determine the size of the array, use the pointer and the malloc ()/* A silly program that copies the argv array and all the pointed – to strings. Just for fun, it also deallocates all the copies. */# include & lt; Stdlib. H> # include & lt; String. H> Int main (int arg c, char * * argv) {char * * new_argv; Int I;/* Since argv [0] through argv [arg c] are all valid, the program needs to the allocate room for arg c + 1 Pointers. */new_argv = (char * *) calloc (arg c + l, sizeof (char *));/* or malloc ((arg c + 1) * sizeof (char *)) */printf (” allocated room for % d Pointers starting at % P \ n “, arg c + 1, new_argv);/* now copy all the strings more (argv [0] through argv [arg c – l]) */for (I = 0; i< argc; + + I) {/ * make room for ‘\ 0’ at end, too */new_argv [I] = (char *) malloc (strlen (argv [I]) + l); Strcpy (new_argv [I], argv [I]); Printf (” % d bytes allocated for new_argv [% d] at % P “, “copied \” % s \ \ “n”, strlen (argv [I]) + l, I, new_argv [I], new_argv [I]); } new_ argv [arg c] = NULL:/* To deallocate everything, get rid of the strings (in any order), then the array of Pointers. If you free the array of poiners first, you lose all the reference To t (I = 0); i< argc; + + I) {free (new_argv [I]); Printf (” freed new_argv [% d] at % P \ n “, I, new_argv [I]); Argv [I] = NULL; * * Habit, see note at the end of this example */} free(new_argv); Printf (” Freed new_argv itself at %P\n”, new_argv); Return 0; /* see 16.4 */}
Note: Why does example 7.5 assign NULL after freeing each element in the new_argv array?This is a habit formed on the basis of long practice. After a pointer is released, you can no longer use the data it originally pointed to, or the pointer is “suspended” and no longer points to any useful data. If a pointer is assigned NULL immediately after it is released, the program will not make an error even if it USES the pointer again. Of course, the program may indirectly refer to the null pointer, but such errors can be detected in time while debugging the program. In addition, a program may still have some original copies of the pointer pointing to the portion of memory that has been freed, which is natural in C programs. In short, although this habit doesn’t solve all problems, it does help.
Matlab errors: Subscript Indices must either be real positive integers or Logicals.Subscript index must be of positive integer type or logical type
Cause of error: in the process of accessing the matrix (including vector, two-dimensional matrix, multidimensional array, same below), the index of the subscript either starts at 0 or has a negative number. Note: The syntax of MATLAB stipulates that the index of the matrix starts from 1, which is different from the habit of programming languages such as C.
Solution: Debug the program yourself and fix subscripts that are zero or negative.
I made a mistake when I was writing the program. I should have done the transpose of the matrix, but I forgot…
Recently, I wrote a small program with many analogisms. For the convenience of compilation, I wrote a Makefile specially for source code and test code.
In the process of debugging, a “Bus error: 10” suddenly appeared, which was quite unexpected. Why did such a spectacular problem occur?
The starting address of type int data must be a multiple of 4, otherwise it will cause the bus error mentioned above. With this in mind, I searched for a long time but couldn’t find any address misaligned.
When I compiled again, I found something fishy about the compilation process. The Makefile compiles the source file “.c/.cpp “into”.o “files (binaries), and then links these”.o “files to target files (executables, libraries, etc.). If some of these files are modified, the Makefile reduces compilation time by detecting the timestamp and compiling only the files that are modified later. So the question is, what happens if you change the header file?Examples are as follows:
Suppose you are going to modify two files, classA.h classa.cpp, add a member variable to the header file, and do the processing in the source file.
The two files classb.cpp classC.cpp will include the classA.h file. Because of the include type, the actual code in the file has been written to the source file and compiled into a “.o “file.
When the modification is completed, there is no change in classb. CPP classc. CPP, so when comparing the timestamp, determine that classb. CPP classc. CPP does not need to be compiled again. However, the header file classA.h of the classb. CPP classC.cpp file has really changed, so when the data is accessed, the address offset of its members will be greatly changed, no error can be found at compile time, but the execution will explode…
Solution: To sum up, it is not difficult to find the problem. The header files held before and after the code are scattered, resulting in running errors. It is only necessary to compile the classes of the modified header files that depend on, and the simple solution is to compile the current project after clean.
This blog is just for the sake of documenting a childish problem you’ve committed: if the header file changes, recompile it all or die…
The above!
So the question is, can the Makefile add dependencies on the source file’s head file?Detects the timestamp of the dependency header file and the “.o “file and compiles them. Make a note of it and study it later.
Codeblocks error:
Debug
ERROR: You need to specify a debugger program in the debuggers’s settings.
(For MinGW compilers, it’s ‘gdb.exe’ (without the quotes))
(For MSVC compilers, it’s ‘cdb.exe’ (without the quotes))
Solutions:
View compiler configuration:
setting -> compiler -> Toochain executables
Record the compiler installation path
Check out the Debuger Setting
setting -> dubuger -> default
Add Executable Path: C:\Program Files (x86)\CodeBlocks\MinGW\bin\ gDB32.exe (note: select GDB.exe for 32-bit system and gdb64.exe for 64-bit system)
sometimes we don’t like to use vs. Dear friends, like to use the eclipse practice c/c + + code, the construction of the environment, portal: http://jingyan.baidu.com/article/17bd8e523d7b9185ab2bb8f2.html span> p>
and then you might follow all the above steps and still hang when you run, and then you need to check the following two places:
1. If you haven’t built the project, click on the following position to build it and run it again. If not, scroll down to see
Note: remote login to Ubuntu12.04 using SecureCRT under Windows 8 using root user account
SecureCRT is a terminal emulator that supports SSH. SecureCRT is used to log into UNIX or Linux server hosts under Windows.
(SSH is short for Secure Shell protocol. Is a security protocol based on the application layer and the transport layer.
error:
Stray ‘\357’ in program
Reason: A full – horn character was typed into the program
.
In the programming, due to the speed of typing, pressing CTRL followed by pressing Space, the system mistakenly detected the CTRL + Space signal and switched the input method from half Angle to full Angle.