You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C++编译错误:expression must have class type 问题求助

问题定位与解决

错误原因

报错expression must have class type but it has type '(Game (*)()'明确说明:代码中的game并不是Game类的实例对象,而是一个返回Game类型对象的函数指针,因此无法通过.运算符调用成员函数running()。

解决方法

  • 检查game的定义:如果你的代码里是这样声明的:
    Game game();
    
    这会被编译器解析为一个返回Game对象的函数声明,而非对象实例。需要改成:
    Game game;
    
  • 如果game确实是有意定义的函数指针,你需要先调用该函数获取Game实例,再调用成员函数:
    // 若函数返回指针
    while (game()->running()) {
        // Update
        // Render
    }
    // 若函数返回值
    while ((*game)().running()) {
        // Update
        // Render
    }
    

内容的提问来源于stack exchange,提问作者Christian B.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 07:17:01