编译器错误C2653:在Visual Studio 17中没有类或名称名称
Compiler error C2653: not a class or namespace name in Visual Studio 17
我知道很多人一直在问这个问题,并且在堆栈溢出上有类似的问题,但我似乎无法理解它们。我希望有人告诉我为什么会发生,但也会发生什么。
我正在编码这个随机程序,以演示如何将类与主文件分开,然后我开始遇到此错误,然后将头发拉出,试图弄清楚如何修复它。
基本上,类.cpp文件不起作用,因为每个功能都在说我的标题文件中的类不是类或命名空间不正确的命名空间。我已经看到了数十次,而且似乎没有任何不合适的拼写,错误或错误地链接,所有文件都在同一项目和文件夹中。
。代码的相关部分:
main.cpp
#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;
}
IQCLASS.H
#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
IQCLASS.CPP
#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...nnn"; //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?nn";
cin >> name;
}
void IQclass::multiplierSelection(){ (ERROR HERE Line 34)
cout << "nWhat should the multiplier be?nn ";
cin >> m;
}
void IQclass::setCycle() { (ERROR HERE Line 39)
cout << "nwhat shoud the cycle be?nn";
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 |
当我在笔记本电脑中键入您的代码时(Win7,VS2015)。同样的错误也会发生。我只是在iqclass.cpp文件中修改一些。
来自:
#include "IQclass.h"
#include "stdafx.h"
to:
#include "stdafx.h"
#include "IQclass.h"
我认为每次都应首先包括#include" stdafx.h"。
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- MSVC多行宏编译器错误
- 编译器错误C2653:在Visual Studio 17中没有类或名称名称
- 编译器错误 C2653:不是类或命名空间名称
- 错误 C2653:'User':不是类或命名空间名称