类 "Requies and Identifier" 中的 int 方法 C++



我正试图从CRC数学表手册中创建一个包含一些数学运算的类,在创建其中一个函数时,我遇到了一个以前从未出现过的奇怪错误。cpp和标头的代码如下:

//Header File
#include <iostream>
#include <cmath>
#include <string>
#define int "CRCMathLib_H"
using namespace std;
class CRCMathLib
{
public:
int DoReturn_Totient(int Toter); //Error comes from here when trying to declare as an int
};
//CPP Class File
#include "CRCMathLib.h"
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int CRCMathLib::DoReturn_Totient(int Toter)
{
return 0;
}
//CPP Main File
#include <iostream>
#include <cmath>
#include <string>
#include "CRCMathLib.h"
using namespace std;
int main()
{
return 0;
}

到目前为止,Main文件还没有做任何事情,因为这是一个用于这些操作的全新文件,我认为这可能是一个预处理错误,当我在另一台带有VS的电脑上运行它时,它没有接收到int语句,并且它能够读取该语句。任何事情都会有帮助。它还请求删除头文件,所以这就是我把int放在那里的原因,这可能是问题所在吗?删除它会返回没有删除的错误。

在.h中删除#define int "CRCMathLib_H",这很可能是一个拼写错误用代替

#include <iostream>
#include <cmath>
#include <string>
#pragma once

#pragma once确保您可以安全地将.h包含在cpp实现文件和main.cpp 中

您错误地理解了通常由进行的防护

ifndef CRCMathLib_H
#define CRCMathLib_H
// all of you .h file delcaration
#endif

这可以很容易地被文件开头的#pragma once语句所取代

点击此处了解更多信息:https://www.learncpp.com/cpp-tutorial/header-guards/

最新更新