C++ 中的 int 方法 Class "Requies and Identifier"
int Method in C++ Class "Requies and Identifier"
我正在尝试制作一个 class 来包含我拥有的 CRC 数学表手册中的一些数学运算,在创建其中一个函数时我遇到了 st运行ge 错误我没有好像以前cpp 和 header 的代码如下:
//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 文件目前还没有做任何事情,因为这是一个用于这些操作的全新文件,我相信这可能是一个预处理错误,并且它没有像我 运行 那样接受 int 语句它在另一台装有 VS 的 PC 上,它能够读取该语句。任何事情都会有所帮助。它还要求删除 header 文件,所以这就是我将 int 放在那里的原因,这可能是问题所在吗?删除它 returns 没有 decleration 的错误。
在你的 .h 中删除 #define int "CRCMathLib_H"
这很可能是一个错字
将其替换为
#include <iostream>
#include <cmath>
#include <string>
#pragma once
#pragma once
确保您可以安全地包含来自 cpp 实现文件的 .h 和 main.cpp
你误解了包括保护通常由
ifndef CRCMathLib_H
#define CRCMathLib_H
// all of you .h file delcaration
#endif
这可以很容易地替换为文件开头的 #pragma once
语句
我正在尝试制作一个 class 来包含我拥有的 CRC 数学表手册中的一些数学运算,在创建其中一个函数时我遇到了 st运行ge 错误我没有好像以前cpp 和 header 的代码如下:
//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 文件目前还没有做任何事情,因为这是一个用于这些操作的全新文件,我相信这可能是一个预处理错误,并且它没有像我 运行 那样接受 int 语句它在另一台装有 VS 的 PC 上,它能够读取该语句。任何事情都会有所帮助。它还要求删除 header 文件,所以这就是我将 int 放在那里的原因,这可能是问题所在吗?删除它 returns 没有 decleration 的错误。
在你的 .h 中删除 #define int "CRCMathLib_H"
这很可能是一个错字
将其替换为
#include <iostream>
#include <cmath>
#include <string>
#pragma once
#pragma once
确保您可以安全地包含来自 cpp 实现文件的 .h 和 main.cpp
你误解了包括保护通常由
ifndef CRCMathLib_H
#define CRCMathLib_H
// all of you .h file delcaration
#endif
这可以很容易地替换为文件开头的 #pragma once
语句