-2

Please have a look at the following code

#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);
    }
}

I am getting the following error when I run this code

"/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)

Why is this? I am new to C++ anyway. Please help!

Griwes
  • 8,805
  • 2
  • 43
  • 70
PeakGen
  • 21,894
  • 86
  • 261
  • 463
  • 1
    First off, you need to specify `vector` in your parameter list, which is kind of useless anyway since `numbers` is global. – chris Oct 07 '12 at 19:13
  • Relevant: [How to pass objects to functions in C++?](http://stackoverflow.com/q/2139224/140719) – sbi Oct 08 '12 at 11:37

3 Answers3

3
Multiple.cpp:8: error: variable or field `isMul' declared void
Multiple.cpp:8: error: missing template arguments before ')' token

std::vector is template, not a complete type; you must specialize isMul's parameter type:

void isMul(vector<int>);

And the real thing you should do, is to grab any book that talks about templates in the "basic" section of the book, read it and then - and only then - proceed to programming.

Griwes
  • 8,805
  • 2
  • 43
  • 70
2

The problem is you haven't given a type for vector in:

void isMul(vector);

If you want a specific type like ints you need:

void isMul(vector<int>);

If you want to template it you should do:

template<class T> void isMul(vector<T>);
CrazyCasta
  • 26,917
  • 4
  • 45
  • 72
0

You should probably read some examples or documentation. There's no such thing like vector type, it's a template. You want to use vector<int> as a parameter type, not just vector to denote vector of ints. Just like you do when you define your vector.

Michael Krelin - hacker
  • 138,757
  • 24
  • 193
  • 173