Error in function call

Getting an error with function call: I am not able to understand

Page 1 of 1

5 Replies - 953 Views - Last Post: 05 November 2008 - 10:32 PM Rate Topic: -----

#1 jingoria  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 96
  • Joined: 22-October 07

Error in function call

Post icon  Posted 05 November 2008 - 09:16 PM

I was writing a program and was compiling regularly to see if there is any error and found this particular function call creating an error that I am not able to understand.
Your help is appreciated.
// HW5_Bhasin.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
using namespace std;
void Erase(int [], int* ,int* );


int main()
{
	char choice;
	const int max = 5;
	int a[max];
	int itemCount=0, SearchElement=0;


	cout<<"Please select from the following menu."<<endl;
	cout<<"	E(Erase Array Content)\tC(Count Words)\tR(Reverse Words)\tQ(Quit)"<<endl;
	cin>> choice;
	cin.ignore();

	switch(choice)
		case 'E':
		case 'e':
		[color=#FF0000]	Erase(a, &itemCount, &SearchElement); // function call giving the error[/color]


	return 0;
}



error list:
Error 1 error LNK2019: unresolved external symbol "void __cdecl Erase(int * const,int *,int *)"
Error 2 fatal error LNK1120: 1 unresolved externals


Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Error in function call

#2 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5363
  • View blog
  • Posts: 27,325
  • Joined: 10-May 07

Re: Error in function call

Posted 05 November 2008 - 09:18 PM

I do not see any reference to a function named "cdecl" in this code. Is it possibly in your custom header file stdafx.h?
Was This Post Helpful? 0
  • +
  • -

#3 GWatt  Icon User is offline

  • member icon

Reputation: 278
  • View blog
  • Posts: 3,078
  • Joined: 01-December 05

Re: Error in function call

Posted 05 November 2008 - 09:25 PM

__cdecl is a compiler instruction or something. The real problem is that jingoria does not define the Erase function.
You have the Erase function declared, but defined nowhere which is probably what is causing your error.
Was This Post Helpful? 0
  • +
  • -

#4 jingoria  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 96
  • Joined: 22-October 07

Re: Error in function call

Posted 05 November 2008 - 09:58 PM

Thanks, I actually solved that particular error: but after resolving that error I got another one: the error is not related the previous error.


#include "stdafx.h"
#include<iostream>
using namespace std;
void Erase(int [], int* ,int* );


int main()
{
	char choice;
	const int max = 5;
	int a[max];
	int itemCount=0, SearchElement=0;


	cout<<"Please select from the following menu."<<endl;
	cout<<"	E(Erase Array Content)\tC(Count Words)\tR(Reverse Words)\tQ(Quit)"<<endl;
	cin>> choice;
	cin.ignore();

	switch(choice)
		case 'E':
		case 'e':
			Erase(a, &itemCount, &SearchElement); 


	return 0;
}

void Erase( int ar[], int *item, int *Search)
{
	

	cout<<"Erase this number"<<endl;

	return;
}




What I understand from the error is that variable max has to be constant, which I have already declared but still get the error.

Also, this particular function is suppose to let user enter an integer value and every occurrence of that integer array needs to be deleted. Can someone give me a hint or an idea how would I delete a particular value in an array.

error list:
Error 1 error C2057: expected constant expression
Error 2 error C2466: cannot allocate an array of constant size 0
Was This Post Helpful? 0
  • +
  • -

#5 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5363
  • View blog
  • Posts: 27,325
  • Joined: 10-May 07

Re: Error in function call

Posted 05 November 2008 - 10:05 PM

My personal favorite :


#define max 5

int main()
{
    char choice;
    int a[max];  // <-- max is set to 5
    int itemCount=0, SearchElement=0;




As long as your max isn't going to change, this is how I would handle it. You can even throw the define in a header file if you prefer.
Was This Post Helpful? 0
  • +
  • -

#6 GWatt  Icon User is offline

  • member icon

Reputation: 278
  • View blog
  • Posts: 3,078
  • Joined: 01-December 05

Re: Error in function call

Posted 05 November 2008 - 10:32 PM

@ jingoria
to delete items from the array you must shift the value of each index after the deleted index up.
void deleteFromArray(int *array, int length, int index)
{
    int i;
    for (i = index; i < length - 1; i++)
        array[i] = array[i + 1];
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1