【发布时间】:2020-02-06 14:45:45
【问题描述】:
我不断收到 cpp 错误,询问我是否忘记在标头中包含 stdafx.h,错误代码是 C1010。
完整的错误是:在寻找预编译的头文件时出现意外的文件结尾。您是否忘记在源代码中添加“#include "stdafx.h""?
首先我有一个头文件,它定义了计算器的一些基本功能。调用时接受参数。
#pragma once
#include <iostream>
#include <string>
#include "stdafx.h"
using namespace std;
class Functions
{
public:
Functions() {};
float add(float a, float b);
float subtract(float a, float b);
float multiply(float a, float b);
float divide(float a, float b);
private:
float answer;
};
然后是 cpp,它简单地计算 2 个参数并返回答案。
#pragma once
#include "Functions.h"
float Functions::add(float a, float b)
{
answer = a + b;
return answer;
}
float Functions::subtract(float a, float b)
{
answer = a - b;
return answer;
}
float Functions::multiply(float a, float b)
{
answer = a * b;
return answer;
}
float Functions::divide(float a, float b)
{
answer = a / b;
return answer;
}
请简单解释一下,我不太擅长编码。
【问题讨论】:
-
将
using放在头文件中是非常糟糕的做法 -
不要将
#pragma once添加到 cpp 文件中,它不会做任何有用的事情