Hello, this is the first time i post on this forum. I am a beginner in C++. I wrote some code in three files (sales.h, saless.cpp and main.cpp) and when i compile the project (I USE DEVC++ compiler in windows 7 32bit) i get the following errors :
[Linker error] undefined reference to `SALES::setSales(SALES::Sales&, double const*, int)'
[Linker error] undefined reference to `SALES::setSales(SALES::Sales&, double const*, int)'
[Linker error] undefined reference to `SALES::setSales(SALES::Sales&, double const*, int)'
[Linker error] undefined reference to `SALES::setSales(SALES::Sales&, double const*, int)'
ld returned 1 exit status
Here follows my code:
sales.h:
#ifndef SALES_H
#define SALES_H
namespace SALES
{
const int QUARTERS = 4;
struct Sales
{
double sales[QUARTERS];
double average;
double max;
double min;
};
void setSales(Sales & s,const double ar[], int n);
void setSales(Sales & s);
void showSales(const Sales & s);
}
#endif
saless.cpp:
#include <iostream>
#include 'sales.h'
using namespace SALES;
void setSales(Sales & s,const double ar[], int n)
{
s.average = 0;
s.max = 0;
s.min = 0;
double sum = 0;
while(s.sales)
{
for(int i=0;i<n;i++)
{s.sales[i] = ar[i];
if(s.sales[i] > s.max)
s.max = s.sales[i];
if(s.sales[i] < s.min)
s.min = s.sales[i];
sum += s.sales[i];
}
}
s.average = sum/n;
}
void setSales(Sales & s)
{
s.average = 0;
s.max = 0;
s.min = 0;
double sum = 0;
std::cout << 'Please enter the values of sales for each quarter belownn';
for(int i=0;i<4;i++)
{ std::cout << 'Quarter #' << i+1 << ': ';
std::cin >> s.sales[i];
std::cout << 'n';
if(s.sales[i] > s.max)
s.max = s.sales[i];
if(s.sales[i] < s.min)
s.min = s.sales[i];
sum += s.sales[i];
}
s.average = sum/4;
};
void showSales(const Sales & s)
{
int size = sizeof(s.sales)/sizeof(double);
for(int i=0;i<size;i++)
{
std::cout << s.sales[i] << 't';
}
std::cout << 'n Max: ' << s.max;
std::cout << 'n Min: ' << s.min;
std::cout << 'n Average : ' << s.average;
};
main.cpp:
#include <cstdlib>
#include <iostream>
#include 'sales.h'
//using namespace sales;
int main()
{
SALES::Sales win;
SALES::Sales mac;
//decalring size of ar[]
int n;
std::cout << 'Enter the number of quarters you wish to insert (<=4 OR >0): ';
std::cin >> n;
while(n<=0 || n>4)
{std::cout << 'You entered invalid value, please try again!';
std::cin >> n;
}
//constructing ar[]
double ar[n];
std::cout << 'Enter the number of sales for each quarter: ';
for(int k=0;k<n;k++)
{std::cout << 'nQuarter #' << k+1 << ': ';
std::cin >> ar[k];
}
//const double sal[n] = ;
//calling functions from saless.cpp
SALES::setSales(win,ar,n);
SALES::setSales(mac);
SALES::showSales(win);
SALES::showSales(mac);
cin.get();
cin.get();
return 0;
}
Thank you for any suggestions!! I just can't find out why I get this error..help :)
[Linker error] undefined reference to `SALES::setSales(SALES::Sales&, double const*, int)'
[Linker error] undefined reference to `SALES::setSales(SALES::Sales&, double const*, int)'
[Linker error] undefined reference to `SALES::setSales(SALES::Sales&, double const*, int)'
[Linker error] undefined reference to `SALES::setSales(SALES::Sales&, double const*, int)'
ld returned 1 exit status
Here follows my code:
sales.h:
#ifndef SALES_H
#define SALES_H
namespace SALES
{
const int QUARTERS = 4;
struct Sales
{
double sales[QUARTERS];
double average;
double max;
double min;
};
void setSales(Sales & s,const double ar[], int n);
void setSales(Sales & s);
void showSales(const Sales & s);
}
#endif
saless.cpp:
#include <iostream>
#include 'sales.h'
using namespace SALES;
void setSales(Sales & s,const double ar[], int n)
{
s.average = 0;
s.max = 0;
s.min = 0;
double sum = 0;
while(s.sales)
{
for(int i=0;i<n;i++)
{s.sales[i] = ar[i];
if(s.sales[i] > s.max)
s.max = s.sales[i];
if(s.sales[i] < s.min)
s.min = s.sales[i];
sum += s.sales[i];
}
}
s.average = sum/n;
}
void setSales(Sales & s)
{
s.average = 0;
s.max = 0;
s.min = 0;
double sum = 0;
std::cout << 'Please enter the values of sales for each quarter belownn';
for(int i=0;i<4;i++)
{ std::cout << 'Quarter #' << i+1 << ': ';
std::cin >> s.sales[i];
std::cout << 'n';
if(s.sales[i] > s.max)
s.max = s.sales[i];
if(s.sales[i] < s.min)
s.min = s.sales[i];
sum += s.sales[i];
}
s.average = sum/4;
};
void showSales(const Sales & s)
{
int size = sizeof(s.sales)/sizeof(double);
for(int i=0;i<size;i++)
{
std::cout << s.sales[i] << 't';
}
std::cout << 'n Max: ' << s.max;
std::cout << 'n Min: ' << s.min;
std::cout << 'n Average : ' << s.average;
};
main.cpp:
#include <cstdlib>
#include <iostream>
#include 'sales.h'
//using namespace sales;
int main()
{
SALES::Sales win;
SALES::Sales mac;
//decalring size of ar[]
int n;
std::cout << 'Enter the number of quarters you wish to insert (<=4 OR >0): ';
std::cin >> n;
while(n<=0 || n>4)
{std::cout << 'You entered invalid value, please try again!';
std::cin >> n;
}
//constructing ar[]
double ar[n];
std::cout << 'Enter the number of sales for each quarter: ';
for(int k=0;k<n;k++)
{std::cout << 'nQuarter #' << k+1 << ': ';
std::cin >> ar[k];
}
//const double sal[n] = ;
//calling functions from saless.cpp
SALES::setSales(win,ar,n);
SALES::setSales(mac);
SALES::showSales(win);
SALES::showSales(mac);
cin.get();
cin.get();
return 0;
}
Thank you for any suggestions!! I just can't find out why I get this error..help :)
C++ Undefined Reference To Function
Fortran Undefined Reference To
May 19, 2012 Hello, this is the first time i post on this forum. I am a beginner in C. I wrote some code in three files (sales.h, saless.cpp and main.cpp) and when i compile the project (I USE DEVC compiler in windows 7 32bit) i get the following errors: Linker error undefined reference to `SALES::setSales(SALES::Sales&, double const., int)'. Apr 09, 2015 Educated guess, how is 'DLLExport' defined? If it is a macro, did you define the right macro to get it defined correctly? Related question. Is the library providing the missing linking function static or shared (DLL)? May 24, 2017 gotoxy is a standard C function defined in, but it will not work in ANSI C compilers such as Dev-C. Line 6 helix vst mac crack 2. Because gotoxy is a Turbo-C specific function, which means it is not part of the standard.