C++ 编译器错误C2653:在Visual Studio 17中不是类或命名空间名称
我知道很多人一直在问这个问题,在堆栈溢出方面也有类似的问题,但我似乎无法理解它们。我希望有人能告诉我为什么会发生这样的事情,以及发生了什么 我编写了这个随机程序来演示如何从主文件中分离类,我开始发现这个错误,我正在努力找出如何修复它 基本上,class.cpp文件不起作用,因为每个函数都说头文件中的类不是不正确的类或命名空间。我已经看了几十遍了,没有任何东西不合适,拼写错误或链接错误,所有文件都在同一个项目和文件夹中 守则的有关部分: main.cpp IQclass.cppC++ 编译器错误C2653:在Visual Studio 17中不是类或命名空间名称,c++,visual-studio,compiler-errors,visual-studio-2017,C++,Visual Studio,Compiler Errors,Visual Studio 2017,我知道很多人一直在问这个问题,在堆栈溢出方面也有类似的问题,但我似乎无法理解它们。我希望有人能告诉我为什么会发生这样的事情,以及发生了什么 我编写了这个随机程序来演示如何从主文件中分离类,我开始发现这个错误,我正在努力找出如何修复它 基本上,class.cpp文件不起作用,因为每个函数都说头文件中的类不是不正确的类或命名空间。我已经看了几十遍了,没有任何东西不合适,拼写错误或链接错误,所有文件都在同一个项目和文件夹中 守则的有关部分: main.cpp IQclass.cpp 当我在我的Lapt
当我在我的LaptoWin7,VS2015中输入您的代码时。同样的错误也会发生。 我只是在IQClass.cpp文件中做了一些修改 发件人: 致:
我认为每次,我们都应该首先包含stdafx.h。当我在我的LaptoWin7,VS2015中输入您的代码时。同样的错误也会发生。 我只是在IQClass.cpp文件中做了一些修改 发件人: 致:
我认为每次我们都应该首先包含stdafx.h。哪行代码报告了这个错误?请放一个@TonyDelroy好的,我想我做了,我没有复制任何最后的错误消息,因为它包含的文件路径太长,这不是问题,所有文件都在同一个文件夹中。谢谢你!我可以确认您的代码删除了非标准include,编译干净,并在我的MacBook上使用clang++运行。您遇到的任何问题都不在代码中,而是在VisualStudio项目配置/生成规则中。我不能帮助你,不是VS用户,但你可以检查一下,如果仍然卡住,可以发布屏幕截图/详细信息。@TonyDelroy我感谢你的帮助,我会确保这样做!哪行代码正在报告该错误?请放一个@TonyDelroy好的,我想我做了,我没有复制任何最后的错误消息,因为它包含的文件路径太长,这不是问题,所有文件都在同一个文件夹中。谢谢你!我可以确认您的代码删除了非标准include,编译干净,并在我的MacBook上使用clang++运行。您遇到的任何问题都不在代码中,而是在VisualStudio项目配置/生成规则中。我不能帮助你,不是VS用户,但你可以检查一下,如果仍然卡住,可以发布屏幕截图/详细信息。@TonyDelroy我感谢你的帮助,我会确保这样做!我赞成这个答案。这解决了我遇到的一个问题。我支持这个答案。这解决了我遇到的一个问题。
#include "stdafx.h"
#include <stdlib.h>
#include <iostream>
#include <time.h>
#include <cstdlib>
#include "IQclass.h"
using namespace std;
int main()
{
IQclass IC;
srand(time(NULL));
IC.nameInput();
IC.multiplierSelection();
IC.setCycle();
IC.forLoop();
return 0;
}
#ifndef IQCLASS_H
#define IQCLASS_H
class IQclass
{
public:
//IQclass();
void nameInput();
void multiplierSelection();
void setCycle();
void calc();
void printIQ();
void randGen();
void forLoop();
};
#endif //IQCLASS_H
#include "IQclass.h"
#include "stdafx.h"
#include <stdlib.h>
#include <iostream>
#include <time.h>
#include <cstdlib>
int y;
long int a;
int m;
int c;
char name[40];
using namespace std;
/* IQclass::IQclass()
{
cout << "\ninitializing...\n\n\n"; //dont ever do this i did it to be funny
typicaly constructers are used to set variables to a defualt state when the
object is created
_sleep(3000);
}
*/
void IQclass::nameInput() (ERROR HERE Line 28)
{
cout << "What is your name?\n\n";
cin >> name;
}
void IQclass::multiplierSelection(){ (ERROR HERE Line 34)
cout << "\nWhat should the multiplier be?\n\n ";
cin >> m;
}
void IQclass::setCycle() { (ERROR HERE Line 39)
cout << "\nwhat shoud the cycle be?\n\n";
cin >> c;
}
void IQclass::calc() { (ERROR HERE Line 44)
a = y*m;
}
void IQclass::printIQ() { (ERROR HERE Line 48)
cout << name << "'s IQ is probably: " << y << endl << "That times: " << m <<
" is " << a << endl << endl;
}
void IQclass::randGen() { (ERROR HERE Line 52)
y = rand() % 160;
};
void IQclass::forLoop() { (ERROR HERE Line 56)
for (int x = 0; x < c;) {
randGen();
calc();
printIQ();
x = x + 1;
};
};
C2653 'IQclass': is not a class or namespace name |File IQclass.cpp | line 28 |
C2653 'IQclass': is not a class or namespace name |File IQclass.cpp | line 34 |
C2653 'IQclass': is not a class or namespace name |File IQclass.cpp | line 39 |
C2653 'IQclass': is not a class or namespace name |File IQclass.cpp | line 44 |
C2653 'IQclass': is not a class or namespace name |File IQclass.cpp | line 48 |
C2653 'IQclass': is not a class or namespace name |File IQclass.cpp | line 52 |
C2653 'IQclass': is not a class or namespace name |File IQclass.cpp | line 56 |
#include "IQclass.h"
#include "stdafx.h"
#include "stdafx.h"
#include "IQclass.h"