Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
338 views
in Technique[技术] by (71.8m points)

c++ - What does this warning "pointer to a function used in arithmetic" mean?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This declaration:

static std::vector<int> race(int v1, int v2, int v3);

declares race to be a static member function that takes 3 int parameters and returns a std::vector<int>.

When you write race[0] the function race decays to a function pointer, and then you're indexing into that. The compiler is warning you that this never makes sense, which is true.

Note that you're only getting a warning instead of an error because you're presumably compiling the code with GCC, which accepts this code as an extension. As far as the language is concerned, this is not allowed, and is an error.

Also, the compiler is not referring to v1, v2, and v3 as functions, it's only referring to race as a function, which is also true.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...