Linux从来没有对我做过:-).与解引用有关的运行时错误 [英] Linux has never done it to me :-). Run time error related to dereferencing
问题描述
我有以下代码:
dcomp *Input(0), *Output(0);
for (int jj = 0; jj <= N-1; jj++)
{
*(Input + jj) = dcomp(0, 0);
Output[jj] = dcomp(0, 0);
}
dcomp是Complex< Double>.我写了两行代码,它们应该以两种不同的方式来清理内存,以表明它们给了我非常相似的警告:
dcomp is Complex<Double>. I wrote two lines that should work to clean the memory in two different ways to show that they give me pretty much the same warnings:
Severity Code Description Project File Line Suppression State
Warning C6011 Dereferencing NULL pointer 'Input+jj'. VerificationOfConcepts c:\users\alexb\onedrive\documents\visual studio 2017\projects\verificationofconcepts\verificationofconcepts\verificationofconcepts.cpp 363 Active
Warning C6011 Dereferencing NULL pointer 'Output'. VerificationOfConcepts c:\users\alexb\onedrive\documents\visual studio 2017\projects\verificationofconcepts\verificationofconcepts\verificationofconcepts.cpp 364 Active
代码可以编译,但是在运行时会中断.消息为:"对象引用未设置为对象的实例"
The code compiles but at run time it breaks. The message is: "Object reference not set to an instance of an object"
出什么问题了?谢谢,-MyCat_Alex
What is the problem? Thanks, - MyCat_Alex
推荐答案
dcomp *Input(0), *Output(0);
for (int jj = 0; jj <= N-1; jj++)
{
*(Input + jj) = dcomp(0, 0);
Output[jj] = dcomp(0, 0);
}
dcomp是Complex< Double>.我写了两行代码,它们应该以两种不同的方式来清理内存,以表明它们给了我非常相似的警告:
dcomp is Complex<Double>. I wrote two lines that should work to clean the memory in two different ways to show that they give me pretty much the same warnings:
Severity Code Description Project File Line Suppression State
Warning C6011 Dereferencing NULL pointer 'Input+jj'. VerificationOfConcepts c:\users\alexb\onedrive\documents\visual studio 2017\projects\verificationofconcepts\verificationofconcepts\verificationofconcepts.cpp 363 Active
Warning C6011 Dereferencing NULL pointer 'Output'. VerificationOfConcepts c:\users\alexb\onedrive\documents\visual studio 2017\projects\verificationofconcepts\verificationofconcepts\verificationofconcepts.cpp 364 Active
代码可以编译,但是在运行时会中断.消息是:"对象引用未设置为对象的实例""
The code compiles but at run time it breaks. The message is: "Object reference not set to an instance of an object"
由于选择了忽略
的警告,因此出现了运行时错误
编译器给了你.输入和输出指针设置为null和
不要指向任何实际的dcomp对象或对象数组.所以
当然,您会收到运行时错误.这是基本的C和C ++
编程.我是否以为您是这些语言的新手?
-韦恩
You got the run time error because you chose to ignore the warnings that
the compiler gave you. The pointers Input and Output are set to null and
do not point to any actual dcomp objects or arrays of objects. So of
course you will get a run time error. This is rudimentary C and C++
programing. Am I to assume that you are new to these languages?
- Wayne
这篇关于Linux从来没有对我做过:-).与解引用有关的运行时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!