error LNK2019: unresolved external symbol
Nov 25, 2011 at 7:41pm UTC
Hey everyone,
I am just learning to program through multiple files and I am getting this error that I can not seem to figure out:
CPPPP CH9Q4.obj : error LNK2019: unresolved external symbol "void __cdecl SALES::setSales(struct SALES::salesStruct &)" (?setSales@SALES@@YAXAAUsalesStruct@1@@Z) referenced in function _main
1>C:\Users\CP\documents\visual studio 2010\Projects\CPPPP CH9Q4\Debug\CPPPP CH9Q4.exe : fatal error LNK1120: 1 unresolved externals
The program is simple, just an exercise of user-defined namespaces, header and source files.
Here is my code:
Sales.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#ifndef SALES_H
#define SALES_H
namespace SALES
{
const int Quarters = 4;
struct salesStruct
{
double salesArray[Quarters];
double average;
double max;
double min;
};
void setSales(salesStruct & s, double ar[], int n);
void setSales(salesStruct & s);
void showSales(const salesStruct & s);
}
#endif
Sales.cpp
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
#include "stdafx.h"
#include "Sales.h"
#include <iostream>
using namespace SALES;
void setSales(salesStruct & s, double ar[], int n)
{
}
void setSales(salesStruct & s)
{
using std::cout;
using std::cin;
using std::endl;
for (int iii = 0; iii < Quarters; iii++)
{
cout << "Enter value number " << iii + 1 << "." << endl;
double n = 0;
cin >> n;
s.salesArray[iii] = n;
}
double total = 0;
for (int iii = 0; iii < Quarters; iii++)
{
total += s.salesArray[iii];
}
s.average = total / Quarters;
s.max = s.salesArray[0];
for (int iii = 1; iii < Quarters; iii++)
{
if (s.max < s.salesArray[iii])
s.max = s.salesArray[iii];
}
s.min = s.salesArray[0];
for (int iii = 1; iii < Quarters; iii++)
{
if (s.min > s.salesArray[iii])
s.min = s.salesArray[iii];
}
}
void showSales(const salesStruct & s)
{
using std::cout;
using std::endl;
for (int iii = 0; iii < Quarters; iii++)
cout << s.salesArray[iii] << " " ;
cout << endl;
}
main.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include "stdafx.h"
#include <iostream>
#include "Sales.h"
int main()
{
using namespace SALES;
salesStruct mystruct;
setSales(mystruct);
showSales(mystruct);
return 0;
}
Last edited on Nov 25, 2011 at 7:58pm UTC
Nov 25, 2011 at 8:00pm UTC
1 2 3 4 5
void SALES::setSales(salesStruct & s)
{
}
// etc...
Also, use
using
on the global scope (outside function definitions) unless you plan to use them just on that particular function. And, instead of
using namespace SALES;
, prefer:
1 2
using SALES::salesStruct;
// etc...
Nov 25, 2011 at 8:17pm UTC
Thanks for the reply! No more unresolved externals!
Topic archived. No new replies allowed.