my first topic!

Hello everyone, I'm brand new to this forum and I need your help already!
When I run my program, I get these errors:

33 C:\Dev-Cpp\Lab 7.cpp expected constructor, destructor, or type conversion before '(' token
33 C:\Dev-Cpp\Lab 7.cpp expected `,' or `;' before '(' token



Here is my code:

#include <iostream>

using namespace std;

const int MAX = 10;
template <typename T>
bool Exists(T data, T array[MAX]);

int main()
{
int iArray[MAX]= {1,3,5,7,11,13,17,19,21,23} ;
char chArray[MAX]={'b','d','e','z','m','c','a','p','s','u'};

//you will have to change the quotes from Mircosofts smart quotes

string strArray[MAX] ={ "John", "Billy", "Bob", "Bruce", "Jorge", "Linda", "Jane", "Alice", "Samantha", "Jack" };


cout<<"Does 2 exist in the integer array?"<<endl;
cout<<Exists(2, iArray)<<endl;

cout<<"Does \'a\' exist in the character array?"<<endl;
cout<<Exists('a', chArray)<<endl;

cout<<"Does \"John\" exist in the string array?"<<endl;
cout<<Exists((string)"John", strArray)<<endl;

system("PAUSE");
return 0;
}


Exists(T data, T array[MAX])
{
int i = 0;

while (i < MAX)
{
if (data == array[i])
{
return true;
}
i++;
}
return false;
}

This is driving me nuts, I know it's a stupid mistake that I am overlooking. Any help is appreciated and thank you in advance!

BTW I am using Dev C++.
Last edited on
You forgot to use template <typename T> before the Exists() function, and it's return value also (bool).
Last you have to include the string header #include <string>

Hope that helps
Last edited on
Thanks for your help! I got it to work :)
Topic archived. No new replies allowed.