““ void *”不是指向对象的指针类型”。在没有void *的代码中?

编程入门 行业动态 更新时间:2024-10-27 01:27:10
本文介绍了““ void *”不是指向对象的指针类型”。在没有void *的代码中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的代码有问题。在 Xcode 中或使用 C ++ 11 编译器,此代码可以很好地工作。但是,当我将此代码提交给在线法官时,判决结果显示为编译错误 。我认为他们使用的是 C ++ 4.7.1 编译器,当我尝试使用Ideone对其进行编译时,它表示:

I have a problem in my code. In Xcode or using the C++11 compiler, this code works well. However, when I am submitting this code to an Online Judge, the verdict shows "Compile Error". I think they use the C++4.7.1 compiler, which when I tried to compile it (using Ideone), it says:

prog.cpp: In function 'void printArray(int)': prog.cpp:27: error: 'void*' is not a pointer-to-object type prog.cpp:27: error: 'void*' is not a pointer-to-object type prog.cpp:27: error: 'void*' is not a pointer-to-object type prog.cpp:27: error: 'void*' is not a pointer-to-object type prog.cpp:27: error: 'void*' is not a pointer-to-object type prog.cpp:27: error: 'void*' is not a pointer-to-object type prog.cpp:27: error: 'void*' is not a pointer-to-object type prog.cpp:27: error: 'void*' is not a pointer-to-object type prog.cpp:27: error: 'void*' is not a pointer-to-object type prog.cpp:27: error: 'void*' is not a pointer-to-object type prog.cpp:27: error: 'void*' is not a pointer-to-object type prog.cpp:27: error: 'void*' is not a pointer-to-object type

这没有任何意义,因为此程序中没有 void *

This makes no sense because there are no void*'s anywhere in this program.

我不虽然没有任何改变。如果你们帮助我解决这个问题,那就太好了。以下是我的代码:

I don't have any inkling what to change though. It would be great if you guys help me to solve this. Below is my code:

#include <iostream> #include <math.h> #include <cmath> #include <tgmath.h> int array[10] = {1,2,3,4,5,6,7,8,9}; int initial = 1; int tmp; int total[500]; using namespace std; void swap(int x, int y){ int temp = array[x]; array[x]=array[y]; array[y]=temp; return; } void printArray(int size){ int i; for (i=0;i<size;i++){ //cout<<array[i]<<" "; tmp= array[i]; tmp= (tmp* (pow(10.0,(size-i-1)))); // <--- Error here total[initial]=total[initial]+ tmp; } initial++; tmp=0; //cout<<endl; } void permute(int k,int size){ int i; if (k==0) printArray(size); else{ for (i=k-1;i>=0;i--){ swap(i,k-1); permute(k-1,size); swap(i,k-1); } } return; } void quickSort(int arr[], int left, int right) { int i = left, j = right; int tmp; int pivot = arr[(left + right) / 2]; while (i <= j) { while (arr[i] < pivot) i++; while (arr[j] > pivot) j--; if (i <= j) { tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; i++; j--; } }; if (left < j) quickSort(arr, left, j); if (i < right) quickSort(arr, i, right); } int main(){ int countertest; cin>>countertest; int ak, asize; for(int a= 0; a<countertest; a++){ initial = 1; std::fill(total, total+500, 0); cin>>asize>>ak; permute(asize,asize); quickSort(total, 1, initial-1); int arraydex [10000], temp = total[ak]; for(int z = asize; z>=0; z--){ arraydex[z] = temp % 10; temp /= 10; } for(int bc = 1; bc<=asize; bc++){ cout<<arraydex[bc]<<" "; } cout<<endl; } return 0; }

推荐答案

据我所知问题是 #include< tgmath.h> ,您可以删除 #include< tmath.h> 同样, #include< cmath> 就足够了。

As far as I can tell #include <tgmath.h> is the issue, and you can remove #include <math.h> as well, #include <cmath> should be sufficient.

如果包括正确的C ++头文件 #include< ctgmath> 看起来还可以。

If you include the proper C++ header file #include <ctgmath> it looks like it is ok as well.

更多推荐

““ void *”不是指向对象的指针类型”。在没有void *的代码中?

本文发布于:2023-06-04 19:06:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/503312.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:指针   对象   类型   代码   void

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!