Witam wszystkich, wiem że podobnych wątków było wiele, ale przeszukałem sporo i nie mogę znaleźć rozwiązania problemu kompilacji wielu plików.
Przy próbie komplilacji programu składającego się z pliku main, sales.cpp,sales.h dostaję taki komunikat błędu. Wszystkie pliki należa do tego samego projektu w tym samym folderze, przy tworzeniu projektu wybieram console aplication. Korzystam z DevC++
C:\Users\Dell\Desktop\Cpp\Project4\main.o main.cpp:(.text+0x84): undefined reference to SALES::SetSales(SALES::Sales&, double const*, int)' C:\Users\Dell\Desktop\Cpp\Project4\main.o main.cpp:(.text+0x90): undefined reference to
SALES::ShowSales(SALES::Sales const&)'
C:\Users\Dell\Desktop\Cpp\Project4\collect2.exe [Error] ld returned 1 exit status
25 C:\Users\Dell\Desktop\Cpp\Project4\Makefile.win recipe for target 'Project1.exe' failed
Jak to naprawić? poniżej kody:
sales.h
#ifndef SALES_H_
#define SALES_H_
namespace SALES{
const int quarters = 4;
struct Sales {
double sales[quarters];
double average;
double min;
double max;
};
void SetSales(Sales &s, const double ar[],int n);
void SetSales(Sales &s);
void ShowSales(const Sales &s);
}
#endif
sales.cpp
#include <iostream>
#include "sales.h"
using namespace std;
using namespace SALES;
void SetSales(Sales &s, const double ar[],int n)
{
double total=0;
double min=ar[0];
double max =ar[0];
for(int i=0; i<n;i++)
{
total+=ar[i];
if(ar[i]<min)
min=ar[i];
else
continue;
}
for(int i=0; i<n;i++)
{
if(ar[i]>max)
max=ar[i];
else
continue;
}
s.average=total/n;
s.max=max;
s.min=min;
s.sales[0]=min;
for(int i=1; i<quarters;i++)
{
s.sales[i]=0;
}
}
void ShowSales(const Sales &s){
cout<<"\nWartosc min = "<<s.min;
cout<<"nWartosc max = "<<s.max;
cout<<"\nWartosci srednia = "<<s.average;
cout<<"\nWartosci tablicy = ";
for(int i=0;i<quarters;i++)
{
cout<<s.sales[i]<<", ";
}
}
main.cpp
#include <iostream>
#include "sales.h"
const int Size=7;
int main() {
using namespace std;
using SALES::SetSales;
using SALES::ShowSales;
using SALES::Sales;
double tablica[Size]={1,2,3,4,5,6,7};
Sales tomek;
SetSales(tomek,tablica,Size);
ShowSales(tomek);
return 0;
}
```cpp.