c++ - main.cpp|45|错误: expected primary-expression before "int" and "double"

标签 c++ c compiler-errors

文件sys.cpp:

#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <string>
#include <fstream>

using namespace std;

[...]

struct kmph_in_mps
        {
            int kmph[4];
            int result[4];


            void kmph_erfassen()
            {
                for (size_t i = 0; i < 4; ++i)
                {
                    cin >> kmph[i];
                }
            }

            void mps_erfassen(int kmph, double result)
            {
                result = kmph / 3.6;
            }

            void ergebniss_ausgeben()
            {
                cout << endl << kmph << "Km/h sind " <<result << " Meter pro Sekunde\n";
            }
        };

[...]

文件main.cpp:

#include <iostream>
#include <stdio.h>
#include <conio.h>
#include "sys.cpp"
#include <fstream>

kmph_in_mps c;


[...]


void Kmph_in_mps()
{
    system("cls");
    cout << "\nKm/h: ";
    c.kmph_erfassen();
    c.mps_erfassen(int kmph, double result);
    c.ergebniss_ausgeben();
    t.beenden();

}

[...]

错误:

Error: expected primary-expression before “int”
Error: expected primary-expression before “double”

我正在学习 C++,我现在不知道该做什么。 我正在互联网和这里寻找答案,但我并没有真正找到合适的答案。 在“in”和“double”之前我必须写哪个主要表达式? 或者我所做的一切都完全错误,就像一个beinner所做的那样? :P

编辑: 我尝试返回结果,但似乎不允许在 void 中。

我已经尝试过c.mps_erfassen();但它也给了我一个错误:错误:没有匹配的函数用于调用“kmph_in_mps::mps_erfassen()”|

我已经尝试过c.mps_erfassen(kmph, result);但我不会在这个范围内声明它们。它们在另一个文件 (sys.cpp) 中声明。 :S

最佳答案

  c.mps_erfassen(int kmph, double result);
              //^^^remove int and double

调用函数时,不应将类型放在参数之前。

关于c++ - main.cpp|45|错误: expected primary-expression before "int" and "double",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26765461/

相关文章:

c - 是否可以在c中使用serialport类?

c - 不断出现段错误

java - 为什么说错误: ';' expected when I compile it?

使用带有泛型类型接口(interface)的 Java 库时的 Scala 编译问题

c++ - 如何将 std::set 的元素添加到另一个非空集?

c++ - 使用父类的重载方法

c++ - 如何解释或缩小此视觉泄漏检测器输出中内存泄漏的原因?

c - 二维数组指针语法 - C

c++ - 调试 websocket++ broadcast_server.cpp ('owner_less' 不是 'std' 的成员)

c++ - 使用多个排序标准对对象 vector 进行排序