““ void *”不是指向对象的指针类型”。在没有void *的代码中? [英] "'void*' is not a pointer-to-object type" in code with no void*'s?

查看:113
本文介绍了““ 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 *的代码中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆