请看下面的代码
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
bool multiple(int,int);
void isMul(vector);
vector <int> numbers;
int enterNumber = 0;
int main()
{
cout << "Enter numbers (-1 to stop entering; -2 to exit)" << endl;
cin >> enterNumber;
while(true)
{
if(enterNumber==-1)
{
isMul(numbers);
break;
}
else
{
numbers.push_back(enterNumber);
cin >> enterNumber;
}
}
}
bool multiple(int number1, int number2)
{
if(number2%number1 == 0)
{
return true;
}
else
{
return false;
}
}
void isMul(vector numbers)
{
cout << "First Number" << setw(10) << "Second Number" << setw(10) << "isMultiplication" << endl;
for(size_t size=0;size<numbers.size();size+2)
{
cout << numbers[size] << setw(12) << numbers[size+1] << setw(12) << multiple(size,size+1);
}
}
运行此代码时出现以下错误
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/cygdrive/c/Users/yohan/Documents/NetBeansProjects/Excersice 6.1'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin-Windows/excersice_6.1.exe
make[2]: Entering directory `/cygdrive/c/Users/yohan/Documents/NetBeansProjects/Excersice 6.1'
mkdir -p build/Debug/Cygwin-Windows
rm -f build/Debug/Cygwin-Windows/Multiple.o.d
g++ -c -g -MMD -MP -MF build/Debug/Cygwin-Windows/Multiple.o.d -o build/Debug/Cygwin-Windows/Multiple.o Multiple.cpp
Multiple.cpp:8: error: variable or field `isMul' declared void
Multiple.cpp:8: error: missing template arguments before ')' token
Multiple.cpp: In function `int main()':
Multiple.cpp:26: error: `isMul' cannot be used as a function
Multiple.cpp: At global scope:
Multiple.cpp:51: error: variable or field `isMul' declared void
Multiple.cpp:51: error: redefinition of `int isMul'
Multiple.cpp:8: error: `int isMul' previously defined here
Multiple.cpp:51: error: missing template arguments before "numbers"
Multiple.cpp:52: error: expected `,' or `;' before '{' token
make[2]: *** [build/Debug/Cygwin-Windows/Multiple.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
nbproject/Makefile-Debug.mk:71: recipe for target `build/Debug/Cygwin-Windows/Multiple.o' failed
make[2]: Leaving directory `/cygdrive/c/Users/yohan/Documents/NetBeansProjects/Excersice 6.1'
nbproject/Makefile-Debug.mk:59: recipe for target `.build-conf' failed
make[1]: Leaving directory `/cygdrive/c/Users/yohan/Documents/NetBeansProjects/Excersice 6.1'
nbproject/Makefile-impl.mk:39: recipe for target `.build-impl' failed
BUILD FAILED (exit value 2, total time: 1s)
为什么是这样?无论如何,我是 C++ 新手。请帮忙!