Weird compiler error?

There is nothing wrong with the code but the compiler throws this error:


1>arrfun3.obj : error LNK2019: unresolved external symbol "void __cdecl show_array(double const * const,int)" (?show_array@@YAXQBNH@Z) referenced in function _wmain

Here's the code in case you want to try it

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// arrfun3.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;

const int Max = 5;

int fill_array(double ar[],int limit);
void show_array(const double ar[], int n);
void revalue(double r, double[], int n);

int _tmain(int argc, _TCHAR* argv[])
{
	double properties[Max];
	int size = fill_array(properties, Max);
	show_array(properties, size);
	cout << "Enter revaluation factor : ";
	double factor;
	cin>> factor;
	revalue(factor,properties, size);
	show_array(properties,size);
	cout << "\nDone. ";
	
	return 0;
}

int fill_array(double ar[],int limit)
{
	double temp;
	int i;
	for (i=0;i<limit; i++)

	{
		cout << "Enter value # " << (i+1) << " : ";
		cin>>temp;
		if(!cin)
		{
			cin.clear();
			while (cin.get() !='\n')
				continue;
			cout << "Bad input; input process terminated";
			break;
		}
		else if (temp <0)
			break;
		ar[i] = temp;
	}

	return i;
}

void showarray(double ar[], int n)
{
	for (int i =0; i < n; i++)
	{
		cout << "Property # " << (i+1) << " :$";
		cout << ar[i] << "\n";
	}
}

void revalue(double r, double ar[], int n)
{
	for (int i=0; i< n; i++)
		ar[i] *=r;
}
Sevenfoxes wrote:
There is nothing wrong with the code but the compiler throws this error:


Famous last words....
Last edited on
lol

Anyway, you're using the function show_array, which is only declared, not defined. I guess your purpose was to define is as you did like showarray. Notice the underscore.
@mag

The compiler still throws the error even when I added the underscore, and yes the function IS defined at the bottom.
@galik

I'm using VC++ 2010 it has a lot of features acts as a kind of "word processor" for common programming mistakes.
closed account (D80DSL3A)
Could the "const" preceeding the 1st argument in the declaration of show_array() be causing this problem? ie. const double ar[] in the declaration vs. double ar[] in the definition?
@Sevenfoxes

I promise you, the compiler is giving you errors because the code is wrong.

First rule of programming: "The compiler is never wrong."
Last edited on
The reason why this will not compile is because the forward declaration of show_array() has a different name and different parameters from the implementation:

void show_array(const double ar[], int n)
In summary:
Your declarations and definitions have to be of the exact same format.

P.S.: Sorry that I didn't saw the const too ;).

I'm using VC++ 2010 it has a lot of features acts as a kind of "word processor" for common programming mistakes.

Like what? (I'm using it too).
Topic archived. No new replies allowed.