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

C++新手求助:编译报错expected primary-expression before ')' token

Troubleshooting Your C++ Compilation Errors

Hey there! As someone who’s struggled through those head-scratching C++ compiler error messages early on, let’s unpack what your errors mean and how to fix them.

First, let’s break down the error you’re seeing:

14:15: error: expected primary-expression before ')' token
18:20: error: expected primary-expression before ')' token

This error basically means the compiler can’t find a valid expression right before that closing parenthesis ). It’s one of the most common syntax hiccups for new C++ developers, and it usually stems from a few key issues:

  • Missing function arguments: If you’re calling a function that requires parameters but forgot to pass them, the compiler gets confused. For example, if you have a function add(int a, int b) and you write add();, this error will pop up.
  • Incomplete conditional expressions: In if, while, or other control structures, if you leave one side of a comparison empty (like if (x > )), the compiler doesn’t know what to compare x against.
  • Typos or undefined identifiers: If you misspell a variable/function name, or reference something the compiler hasn’t seen yet, it might interpret that as a missing expression before a parenthesis.
  • Macro or template syntax mistakes: Sometimes macros can mess with parentheses, or template arguments might be missing or misformatted.

To give you a concrete example, here’s some code that would trigger exactly this error:

#include <iostream>

void greet(std::string name);

int main() {
    greet(); // Line with error: no argument passed to greet()
    if (5 > ) { // Another error: missing right-hand side of comparison
        std::cout << "Number is big!" << std::endl;
    }
    return 0;
}

void greet(std::string name) {
    std::cout << "Hello, " << name << "!" << std::endl;
}

Since you mentioned lines 14 and 18 are the problem spots, could you share the code around those lines (or a minimal, complete example that reproduces the error)? That way I can pinpoint exactly what’s causing the issue and walk you through fixing it step by step.

内容的提问来源于stack exchange,提问作者andre2539

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 07:40:54