C++ error C2100: illegal indirection 问题

本文通过一个示例程序展示了C++中指针与数组的常见错误用法及正确处理方式,包括如何避免非法间接寻址错误并正确输出数组元素。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

源程序如下:

#include <iostream>
using namespace std;

int main()
{
      int *pint = new int( 1024 );
      int *pia = new int[4];

    for(int i=0; i<4; i++)
 {
      *pia[i] = 1025 + i;            //错误位置

      cout << *pia[i] << "  ";     //错误位置
 }

 cout << endl << *pint << endl;

 delete pint;
 delete []pia;

 return 0;
 
}

编译时出现错误如:error C2100: illegal indirection

如下修改:

#include <iostream>
using namespace std;

int main()
{
       int *pint = new int( 1024 );
       int *pia = new int[4];

    for(int i=0; i<4; i++)
 {
        pia[i] = 1025 + i;

        cout << pia[i] << "  ";
 }

 cout << endl << *pint << endl;

 delete pint;
 delete []pia;

 return 0;
 
}

Error using loadlibrary Building ueye_thunk_pcwin64 failed. Compiler output is: cl -I"C:\Program Files\MATLAB\R2024b\extern\include" /Zc:__cplusplus /Zp8 /W3 /nologo -I"C:\Users\bio\Desktop\Zhenyu" -I"C:\Program Files\IDS\uEye\develop\include" "ueye_thunk_pcwin64.c" -LD -Fe"ueye_thunk_pcwin64.dll" ueye_thunk_pcwin64.c ueye_thunk_pcwin64.c(567): error C2059: syntax error: ')' ueye_thunk_pcwin64.c(567): error C2061: syntax error: identifier 'INT__cdeclis_ExitImageQueue' ueye_thunk_pcwin64.c(567): error C2059: syntax error: ';' ueye_thunk_pcwin64.c(568): error C2143: syntax error: missing ')' before '{' ueye_thunk_pcwin64.c(569): error C2059: syntax error: ')' ueye_thunk_pcwin64.c(569): error C2065: 'deprecated': undeclared identifier ueye_thunk_pcwin64.c(569): error C2146: syntax error: missing ';' before identifier 'INT' ueye_thunk_pcwin64.c(569): error C2275: 'INT': expected an expression instead of a type ueye_thunk_pcwin64.c(569): error C2143: syntax error: missing ';' before '__cdecl' ueye_thunk_pcwin64.c(570): error C2065: 'p0': undeclared identifier ueye_thunk_pcwin64.c(570): error C2065: 'deprecated': undeclared identifier ueye_thunk_pcwin64.c(570): error C2100: you cannot dereference an operand of type 'int' ueye_thunk_pcwin64.c(570): error C2146: syntax error: missing ';' before identifier 'INT' ueye_thunk_pcwin64.c(570): error C2275: 'INT': expected an expression instead of a type ueye_thunk_pcwin64.c(570): error C2143: syntax error: missing ';' before '__cdecl' ueye_thunk_pcwin64.c(571): error C2065: 'p0': undeclared identifier ueye_thunk_pcwin64.c(571): error C2065: 'p0': undeclared identifier ueye_thunk_pcwin64.c(571): error C2065: 'p0': undeclared identifier ueye_thunk_pcwin64.c(572): error C2059: syntax error: ')' Error in control (line 9) loadlibrary(dllPath, headerPath, 'alias', 'ueye'); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >>
最新发布
07-24
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值