这是一个旨在使用ppm图像文件的程序。
我在尝试使用接受全局结构变量并提取该图像成员的函数时遇到编译错误。
这是全局结构(在ppmIO.c和ppmIO.h中声明):
ppmIO.c:
struct Image *instance;
ppmIO.h:
struct Image { int width; int height; unsigned char *data; }; extern struct Image *instance;
这就是我从main调用我的函数的方法:
ImageInvert(&instance);
这些是我的imageManip.c文件的相关部分:
#include #include #include #include #include void ImageInvert(struct Image **toInvert) { int i; int pix = (*toInvert->width) * (*toInvert->height); for (i = 0; i data = ((unsigned char)255 - *(toInvert)->data)); *(toInvert)->data = ((unsigned char)255 - *(toInvert)->data++)); *(toInvert)->data = ((unsigned char)255 - *(toInvert)->data++)); } }
这是我的imageManip.h文件:
#include void ImageInvert(struct Image **toInvert); void ImageSwap(struct Image **toSwap);
这些是我得到的错误:
imageManip.c:31:23: error: request for member 'width' in something not a structure or union int pix = (*toInvert->width) * (*toInvert->height); ^ imageManip.c:31:44: error: request for member 'height' in something not a structure or union int pix = (*toInvert->width) * (*toInvert->height); ^ imageManip.c:35:18: error: request for member 'data' in something not a structure or union *(toInvert)->data = ((unsigned char)255 - *(toInvert)->data)); ^ imageManip.c:35:60: error: request for member 'data' in something not a structure or union *(toInvert)->data = ((unsigned char)255 - *(toInvert)->data)); ^ imageManip.c:35:67: error: expected ';' before ')' token *(toInvert)->data = ((unsigned char)255 - *(toInvert)->data)); ^ imageManip.c:35:67: error: expected statement before ')' token imageManip.c:36:18: error: request for member 'data' in something not a structure or union *(toInvert)->data = ((unsigned char)255 - *(toInvert)->data++)); ^ imageManip.c:36:60: error: request for member 'data' in something not a structure or union *(toInvert)->data = ((unsigned char)255 - *(toInvert)->data++)); ^ imageManip.c:36:69: error: expected ';' before ')' token *(toInvert)->data = ((unsigned char)255 - *(toInvert)->data++)); ^ imageManip.c:36:69: error: expected statement before ')' token imageManip.c:37:18: error: request for member 'data' in something not a structure or union *(toInvert)->data = ((unsigned char)255 - *(toInvert)->data++)); ^ imageManip.c:37:60: error: request for member 'data' in something not a structure or union *(toInvert)->data = ((unsigned char)255 - *(toInvert)->data++)); ^ imageManip.c:37:69: error: expected ';' before ')' token *(toInvert)->data = ((unsigned char)255 - *(toInvert)->data++));
不确定我是否正确访问了成员,或者我是否正确使用指针…
我是如何使用括号的。
这是imageInvert函数的工作版本:
void ImageInvert(struct Image **toInvert) { int i; int pix = (*toInvert)->width * (*toInvert)->height; for (i = 0; i < pix; i++) { (*toInvert)->data = ((unsigned char)255 - (unsigned char)(*toInvert)->data); (*toInvert)->data = ((unsigned char)255 - (unsigned char)(*toInvert)->data++); (*toInvert)->data = ((unsigned char)255 - (unsigned char)(*toInvert)->data++); } }
以上就是c/c++开发分享c – 错误:在非结构或联合的情况下请求成员xxxxxx相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/519137.html