【发布时间】:2015-11-14 23:59:15
【问题描述】:
我的下一个代码有问题,我收到错误:invalid type argument of unary '*' (have 'int')。如果我写了int *content 允许代码运行,但我必须写int=content 并更改代码*((ptab->content)+pC1+17),我尝试了但无法修复错误。
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <conio.h>
#include <iomanip>
#include <stdio.h>
#include <Windows.h>
using namespace std;
struct box{
int content;
};
struct box *ptab;
int pC1=5;
int main (){
ptab=new struct box[64];
if (*((ptab->content)+pC1+17)==0) {
pC1=pC1+17;
}
cout<<pC1<<endl;
}
我必须从指向指针的指针传递到结构数组,这段代码是一个例子,因为原始代码有 23000 行。
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <conio.h>
#include <iomanip>
#include <stdio.h>
#include <Windows.h>
using namespace std;
int *box;
int pC1=5;
int main (){
box=new int[64];
if (*(box+pC1+17)==0){
pC1=pC1+17;
}
cout<<pC1<<endl;
}
【问题讨论】:
-
你不能取消引用这个表达式:
((ptab->content)+pC1+17) -
你实际上想在这段代码中做什么?正确的输出是什么? (有多种方法可以编译它,但从你的问题中不清楚你想要哪一个 - 它们有不同的含义。)
-
我很乐意提供比“重新考虑您在这里尝试的内容”更好的建议,但我不知道您要做什么。对此代码目标的更好解释可能会提供更好的结果。
-
我还有其他游戏代码,该代码有 23000 行,我必须从指针传递到指向结构数组的指针
-
我编辑问题并用指针编写代码,谢谢 =)
标签: c++ arrays pointers struct invalid-argument