Tag Archives: C/C++

Some problems in using arrays

/*
* array note some issues
*/
#include < iostream>
using namespace std;
Int main()
{
const int ArraySize = 5;
// initializes the elements in the array, and the uninitialized elements are by default filled with the value 0, representing the NULL character (NULL or \0)
int arr[ArraySize] = {10,3,5};

// array name, which represents the starting address of the first element (direct array name is recommended)
cout < < “arr = ” < < arr < < endl;
// array is a collection, take the address of the array name, get is the first address of the collection represented by the array (generally not recommended to use the address of the array name)
cout < < “& arr = ” < < & arr < < endl;

{
/* array name itself is not a variable, so it does not occupy storage space, nor can it be used to store data; ,
, which simply represents a data, as a value, it represents the address of the first data element in the array. */
// for example, the following is wrong!!
/* compile times wrong: assigning to an array from the an, initializer list */
// arr = {10,16,8};
// therefore, arrays cannot be assigned, only array elements can be initialized or assigned.
}
// if an array is defined and not initialized, its output will be garbage instead of having no value
/*cout < < “No array initialization, garbage data output!” < < endl;
for(int I = 0; i ! = ArraySize; I++)
cout & lt; < arr[i] < < “‘;
cout & lt; < endl;

// input data, assign values to data elements in arr array
/* even if the number of input data elements is greater than the length of the array, cin will only extract required data from the input buffer according to the length of the array
, while the remaining data will be left in the input buffer for use next time */
//cout < < “The input data are:”;
//for(int I = 0; i ! = ArraySize; I++)
// cin & gt; > arr[i];

// below are three different ways to output the address of each array element in memory
/*cout < < “Method 1:” < < endl;
for(int I = 0; i ! = ArraySize; I++)
cout & lt; < “& arr[” << i << “] = ” < < & arr[i] < < endl;
cout & lt; < “Method two:” < < endl;
for(int I = 0; i ! = ArraySize; I++)
cout & lt; < “[arr+” << i << “] = ” < < arr+i < < endl;
cout & lt; < “Method 3:” < < endl;
for(int I = 0,*p = arr; p ! = (arr+ArraySize) & & i ! = ArraySize; I++ p++)
cout & lt; < “p -[” << i << “]= ” < < p < < endl; */

/* the following four methods of outputting elements in an array have no errors;
the compiler changes the brackets in the array at compile time :(both sides are equivalent to each other)
arr[I] < => * (arr + I)
* (arr + I) & lt; => * (I + arr)
* (I + arr) & lt; => I (arr)
arr [I] < => I [arr]
I is the offset, indicating the number of elements of the offset first element */
/*for(int I = 0; i ! = ArraySize; I++)
cout & lt; < arr[i] < < “‘;
cout & lt; < endl;
For (int I = 0; i ! = ArraySize; I++)
cout & lt; < *(arr+i) < < “‘;
cout & lt; < endl;
For (int I = 0; i ! = ArraySize; I++)
cout & lt; < i[arr] < < “‘;
cout & lt; < endl;

for(int* p = arr; p ! = (arr+ArraySize); P++)
cout & lt; < *p < < “‘;
cout & lt; < endl; * /

cout <
cout < < “The consequences of a cross-border visit!” < < endl;
int iNum = 123,iLen = 90;
int array[7] = {10,3,6,8,5,9,7};
for(int I = -2);
for(int I = -2);
for(int I = -2); i ! = 9; I++)
cout & lt; < array[i] < < “‘;
cout & lt; < endl;

cout & lt; < iNum < < “—” < < iLen < < endl;
// Out-of-bounds storage of data can result in the value of other variables, and may even cause the program to crash (which didn’t happen, which is weird!!).
for(int I = -2; i ! = 7. I++)
cin & gt; > array[i];
for(int I = 0; i ! = 7. I++)
cout & lt; < array[i] < < “‘;
cout & lt; < endl;
cout & lt; < iNum < < “—” < < iLen < < endl;
return 0;
}

C++ ERROR redefinition of ‘class ***’

The error is as follows:
BaseSmoothingAlgorithm. H: 4:7: error: redefinition of “class BaseSmoothingAlgorithm ‘
BaseSmoothingAlgorithm. H: 4:7: error: the previous definition of ‘class BaseSmoothingAlgorithm’
Troubleshooting steps:
1. Find whether there are fewer classes “; “after the definition of the class. ; Find one after another, not this type of error
2. There are no macros to prevent them from being included more than once
#ifndef _BASESMOOTHINGALGORITHM_H_
#define _BASESMOOTHINGALGORITHM_H_
#include “BaseSmoothingAlgorithm.h”
#endif
To solve

[C + +] G + + compiler class template error message: template argument 1 is invalid

template< typename T>

NamedObject< typename T> ::NamedObject(const char *name, const T& The definition format of value can be compiled smoothly in VS,

but error: template argument 1 is invalid in GCC and should be defined as removing the second typename

template< typename T>

NamedObject< T> ::NamedObject(const char *name, const T& value)

Error c2143: syntax error: missing ‘;’ before ‘type’

When using VC6.0 to compile. C file, if you define variables in any place in the program, the above error will occur;
Reason: Generally in ANSI C or C++, it is allowed to define variables at any time in executable code, but in K& It’s not allowed in R and C, and that’s why we have this error. VC6.0, VS2008 are used K& R C to implement the C language, so the compilation process will report errors.
In pure C, variable declarations for a block of code are usually at the front end.
Solution: 1. Put all variable declarations at the beginning.
2. Save the file as. CPP file.
 
 

OpenGL runtime returned 1283 (stack overflow) error

During the test, it was found that some models would cause OpengL to report 1283 error. The code is as follows:

// check for errors
	m_glErrorCode=glGetError();
	if(m_glErrorCode != GL_NO_ERROR)
	{
		const GLubyte *estring;
		CString mexstr;
// get the error descritption from OGL
		estring = gluErrorString(m_glErrorCode);
// prepare and show a message box
		mexstr.Format(L"GLEnabledView:\n\tAn OpenGL error occurred: %s\n", estring);
		AfxMessageBox(mexstr,MB_OK | MB_ICONEXCLAMATION);
	}

The value of m_glErrorCode for debugging is 1283 and eString is a stack overflow
After talking to friends and Googling, I came to the following conclusion:
The push and POP classes in OpengL don’t match.
The reason for the problem is that after a push, an opengL function made an error running, and then the return dropped, causing the subsequent POP not to run, reporting the error.

After the problem is solved, I find that the previous code will make a judgment on the return value of some OpengL functions. Let’s learn. This will help you find out quickly what the problem is.

	if(!gluUnProject(winx,winy,winz,modelMatrix,projMatrix,viewport,&objx1,&objy1,&objz1))
		return FALSE;

If you want to discuss it, please email me.

fatal error C1001: INTERNAL COMPILER ERROR

Xiaobai is going through operator overloading in c++ today. In the process of debugging, an error was found as follows:
E:\ Work \C-C++\ Practice \ Capter10 \10-3\10-3. CPP (11) : Fatal Error C1001: INTERNAL COMPILER error (COMPILER file ‘mSC1.cpp ‘, line 1786)

Please choose the Technical Support command on the Visual C++

Help menu, or open the Technical Support Help file for more information

An error occurred while executing cl. Exe.
Xiaobai checked the code back and forth for 3 times, and found nothing unusual. The results after searching for a circle on the Internet are as follows:
This error is due to a bug in Microsoft visual Stdio 2008 (V6.0). The C++ standard has not been fully implemented in V6.0. The header file provided without the suffix. H does not support the operator overloading function as a friend function, but the older version of visual C++ with the suffix. H can support this function (such as method 2).
Method one:
will
#icnlude< iostream>
using namespace std;
Replace:
#include< iostream>
using std : : cout ;
using std : : endl ;
Method 2:
will

#icnlude< iostream>
using namespace std; Replace:
#include< iostream.h>

Error tips:array type has incomplete element type

error:array type has incomplete element type

This is generally because when a header file USES a custom variable type, the declaration of the variable type does not appear in the header file, that is, it is not declared before it is used. The
solution is to add the header file that declares the variable type to the header file used.

VS2010 error: LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt

After installing VS2012, an error occurred while using VS2010

LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt

The solution is simple, as follows:

To summarize:
Either disable incremental linking, by going to

Project Properties 
   -> Configuration Properties 
       -> Linker (General) 
          -> Enable Incremental Linking -> "No (/INCREMENTAL:NO)"

or install VS2010 SP1.
VS2010 SP1 patch download address: http://www.microsoft.com/en-us/download/details.aspx?id=23691

Reference:
http://stackoverflow.com/questions/10888391/link-fatal-error-lnk1123-failure-during-conversion-to-coff-file-invalid-or-c

.. ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status make[2]: ***

2019 Unicorn enterprise heavily recruited Python engineer standard & GT; > >

./configure –prefix=/usr/local/nginx –with-http_ssl_module –with-http_stub_status_module –add-module=/usr/local/ngx_devel_kit-0.3.0 –add-module=/usr/local/ lua-nginx-Module-0.10.6 – add – the module =/usr/local/echo – nginx – module – 0.60
– with – cc – opt = “-i/usr/local/Cellar/pcre/8.39/include” – with – ld – opt = “-l/usr/local/lib/Cellar/pcre/8.39”
 
 
The e problem that had puzzled us for two days was finally solved.
Increase these two parameters
– with – cc – opt = “-i/usr/local/Cellar/pcre/8.39/include” – with – ld – opt = “-l/usr/local/lib/Cellar/pcre/8.39”
 

Reproduced in: https://my.oschina.net/cooler1217/blog/736886

C + +: error in X utility file

In the middle of writing the program and testing it, there were a bunch of syntax errors that came from xUtility files.
opens the xutility file, which defines many constructs and function templates. Find the source of the error is not found, because it is similar to the lack of; “And so on. So back before writing the code, and finally found the problem: in the global defines a short function, then the short function and a function template name repetition, combined with the incoming parameters when calling type does not conform to the global defines the type of function, to the template, but does not define the type of template function, hence lead to errors.
correction method:
1. Change function name, error parameter type will report the correct position
2. Use scope to avoid ambiguity caused by improper parameter types

Error lnk1123: failure during conversion to coff: problem solving

I encountered this problem today while building a debug version of a program. What’s strange to me is that if it’s a release version it won’t have this problem, debug will. I am very confused, the Internet to find some information, mainly there are several ways:
1. Modify the following configuration
Project Properties
-> Configuration Properties
-> Linker (General)
-> Enable Incremental Linking -> “No (/INCREMENTAL:NO)”
I tried and failed to solve the problem.
2. Rename or delete cvtres.exe file
The default path for the file in VS2010 is: C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\cvtres.exe
With a pinch of salt, rename the CVtres.exe and rebuild it to find it passed. That’s strange.