【发布时间】:2020-02-19 23:51:04
【问题描述】:
所以我使用 Visual Studio 在 C++ 中创建了一个代码,并且我正在学习制作类和使用方法/函数。该程序运行良好,直到我写了using namespace std; 并突然尝试运行我的代码我得到了一个 LNK1168 错误,我尝试了一切来修复它。
我确保没有任何任务在运行,我保存并关闭它并重新打开它以再次运行它,但无论我做什么,LNK1168 错误都会再次弹出。
然后我从调试 x86 切换到调试 x64,我的代码在 x64 上正常工作。
这有关系吗?如果是为什么,如果不是那我该怎么办?
#include<iostream>
// did not include the using namespace std; because that's when my issue started
// not sure if it had something to do with it
class Player
{
public:
int x, y;
int speed;
void movin(int xa, int ya)
{
x += xa * speed;
y += ya * speed;
}
};
int main()
{
Player player;
player.movin(1, 1);
std::cout << "apples are tasty"; // this is to make sure my code prints something
std::cin.get();
return 0;
}
我尝试查找 youtube 视频,但没有任何帮助!奇怪的是 x64 可以工作,但不是通常的 x86?这会影响我的代码或我如何编译我的代码吗?它会让事情运行得更慢吗?我很困惑。 单击错误后,我尝试查看 Windows 帮助站点,但没有任何帮助。有人知道吗?
【问题讨论】:
-
你可能会做一些其他的改变。上面在 x86 和 x64 中带有“命名空间 std”语句的代码在 VisualStudio 2019 上成功运行。
标签: c++