[英]Returning a Function Pointer in C++
這是代碼:
void (*)(const dpp::slashcommand_t &event) operator[](const std::string &index);
當我編譯它時,我收到以下錯誤消息:
In file included from commands_controller.cpp:3,
from main.cpp:2:
commands_controller.h:28:12: error: expected unqualified-id before ‘)’ token
28 | void (*)(const dpp::slashcommand_t &event) operator[](const std::string &index);
你對我如何解決這個錯誤有什么建議嗎?
在處理函數指針時,使用 typdefs。 正確的非 typedef 語法是:
void (*operator[](const std::string &index))(const dpp::slashcommand_t &event)
https://coliru.stacked-crooked.com/a/4eabda845ac15a54
顯然,這完全是瘋了。
因此,始終使用 typedef 或別名:
using slash_fn_ptr = void (*)(const dpp::slashcommand_t &event);
slash_fn_ptr operator[](const std::string &index);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.