爲什麼我從編譯器中獲得this error關於不帶0參數的函數?是因爲我在被調用之後聲明函數?C++函數不接受0參數
// HelloWorld.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!\n";
cout << "Game over!\n";
swap();
system("pause");
return 0;
}
int swap()
{
int on = 1;
int off = 0;
int temp = on;
on = off;
off = temp;
return 0;
}
您需要在使用它之前聲明的一切。 –
避免'使用namespace std'並定義一個具有相同名稱的函數...... – Jarod42
這是因爲你被代碼中'using namespace std;'行燒燬了。猜猜編譯器從哪裏獲得'swap'? – PaulMcKenzie