c++ - 无法编译(未声明且预期的主表达式)

标签 c++ mysql regex struct

下面是一个将被主程序调用的函数。我的问题是,如果我不将 challInfo 声明为结构体,则在编译时,它将返回:

ERROR on page PhotoPoints at line 5, col 21: ‘challInfo’ was not declared in this scope

同时,如果我声明它(如下所示),它会返回:

ERROR on page PhotoPoints at line 5, col 30: expected primary-expression before ‘.’ token ERROR on page PhotoPoints at line 7, col 52: expected primary-expression before ‘.’ token ERROR on page PhotoPoints at line 8, col 28: expected primary-expression before ‘.’ token ERROR on page PhotoPoints at line 8, col 60: expected primary-expression before ‘.’ token ERROR on page PhotoPoints at line 8, col 109: expected primary-expression before ‘.’ token ERROR on page PhotoPoints at line 9, col 31: expected primary-expression before ‘.’ token ERROR on page PhotoPoints at line 9, col 66: expected primary-expression before ‘.’ token ERROR on page PhotoPoints at line 9, col 118: expected primary-expression before ‘.’ token ERROR on page PhotoPoints at line 14, col 35: expected primary-expression before ‘.’ token ERROR on page PhotoPoints at line 14, col 57: expected primary-expression before ‘.’ token

我一直在互联网上查找,包括 Stack Overflow,似乎这个问题的答案总是针对每种情况。我承认我迷路了。你能帮忙吗?

float PhotoPoints() {
struct challInfo; 
  bool isFacingOther();
  bool sphereInDark();
  bool isCameraOn = challInfo.camera.cameraOn;
  bool isFacingOtherResult = isFacingOther();
  bool isOppNotInDarkZone = !sphereInDark(challInfo.other.zrState);
  bool myMirror = challInfo.me.mirrorTime != 0 && challInfo.me.mirrorTime + ITEM_MIRROR_DURATION > challInfo.currentTime;
  bool otherMirror = challInfo.other.mirrorTime != 0 && challInfo.other.mirrorTime + ITEM_MIRROR_DURATION > challInfo.currentTime;
  float picturePointValue = 0;
  if (isCameraOn && isFacingOtherResult && isOppNotInDarkZone && !myMirror)
  {
    float bet[3], distance;
    mathVecSubtract(bet, challInfo.me.zrState, challInfo.other.zrState, 3);
    distance = mathVecMagnitude(bet, 3);

    if (distance < PHOTO_MIN_DISTANCE) {
      DEBUG(("Not a good shot: too close to the other satellite | "));
      return 0.0;
    }
    picturePointValue = 2.0 + 0.1/(distance - PHOTO_MIN_DISTANCE + 0.1);
    if(otherMirror){
      picturePointValue = 0;
      DEBUG(("Not a good shot: Opposing mirror active |"));
    }

  }
  else if(!isCameraOn){
    DEBUG(("Not a good shot: camera off |"));
  }
  else if(myMirror){
    DEBUG(("Not a good shot: my mirror's in the way |"));
  }
  else if(!isFacingOtherResult) {
        DEBUG(("Not a good shot: not facing the other satellite | "));
    }
  else if(!isOppNotInDarkZone){
    DEBUG(("Not a good shot: opponent in dark zone |"));
  }
  return picturePointValue;
}

最佳答案

每次引用 challInfo 的成员时,都会出现错误。您需要包含完整的声明,以便编译器可以告诉结构体内部的内容,简单地说它是一个结构体。您仅提供了前向声明。

关于c++ - 无法编译(未声明且预期的主表达式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32890795/

相关文章:

c++ - 错误:'std::cout 中的 'operator<<"不匹配

java - 正则表达式抛出异常索引超出 unicode char 的范围?

php - 如何从 preg_split 结果中删除空数组?

java - java 验证电子邮件格式

c++ - CMake 和绝对标题路径

c++ - 调整 Windows 控制台和 MFC 静态库的大小

c++ - 移动时鼠标光标消失

mysql - 当数据不为空时如何合并不同列的数据?

mysql - 列的字符串值不正确

php - 如何调出每个产品的最后一个条目