这是什么意思(C ++):“警告:指向算术[Wpointer-arith]中使用的函数的指针"? [英] What does this mean (C++): "warning: pointer to a function used in arithmetic [Wpointer-arith]"?

查看:288
本文介绍了这是什么意思(C ++):“警告:指向算术[Wpointer-arith]中使用的函数的指针"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个C ++程序,并且有一个警告不断出现(我正在使用g ++):

I am making a C++ program and I have a warning that keeps cropping up (I'm using g++):

warning: pointer to a function used in arithmetic [Wpointer-arith]

,我想知道:此警告消息到底是什么意思?编译器试图告诉我的问题是(一般而言),以便我可以更好地理解我在做什么错了?

and I want to know: what exactly does this warning message mean? What is my compiler trying to tell me the problem is (in general terms) so I can better understand what I'm doing wrong?

Google搜索为人们代码中的特定问题提供了特定的解决方案,但从不告诉我该警告消息要说的是什么.

Google searches turn up specific solutions to specific problems in people's code, but never tell me exactly what this warning message is trying to say.

我只是在学习数组,并且正在尝试制作一个打印"Hello,world!"的程序.一次一个字符,每个字符分别存储在一个数组中,并在for循环中泵送到cout.

I'm just learning arrays and I'm trying to make a program that prints "Hello, world!" one character at a time, each character being stored individually in an array and pumped to cout in a for loop.

这是代码:

#include <iostream>
using namespace std;

int ARRAY_ELEMENTS = 14;

void greeting()
{
    char greeting[ARRAY_ELEMENTS];
    greeting[0] = 'H';
    greeting[1] = 'e';
    greeting[2] = 'l';
    greeting[3] = 'l';
    greeting[4] = 'o';
    greeting[5] = ',';
    greeting[6] = ' ';
    greeting[7] = 'w';
    greeting[8] = 'o';
    greeting[9] = 'r';
    greeting[10] = 'l';
    greeting[11] = 'd';
    greeting[12] = '!';
    greeting[13] = '\0';
}
int main(int argc, char* argv[])
{
    greeting();
    for (ARRAY_ELEMENTS = 0; 
        ARRAY_ELEMENTS <= 13;
        ARRAY_ELEMENTS++)
    {
        cout << greeting[ARRAY_ELEMENTS] << endl;
    }
    return 0;
}

谢谢您的时间.

推荐答案

在此行:

cout << greeting[ARRAY_ELEMENTS] << endl;

您指的是名为 greeting 函数,您将其视为一个数组.

you are referring to the function named greeting that you're treating as if it were an array.

这篇关于这是什么意思(C ++):“警告:指向算术[Wpointer-arith]中使用的函数的指针"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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