   namespaces and linker error
  I use a header file, a cpp file with function definitions for the header file and a main file. What is failing is the main file and I don't really know why.The header file "sales.h" looks like this:#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); }#endifall the function definititions in the sales.cpp file compiled succefully togheter with the header file, but when I add a main file which uses the functions, the following linker errors appears:[Linker error] undefined reference to `SALES::setSales(SALES::Sales&)'[Linker error] undefined reference to `SALES::setSales(SALES::Sales&)' [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::showSales(SALES::Sales const&)' [Linker error] undefined reference to `SALES::showSales(SALES::Sales const&)' I have included the "sales.h" file into the main.cpp file.I have added the using directive in the main.cpp file.The sales.cpp file also contains the header include and using directive.What am I missing?   
Quote:Original post by passwordWhat am I missing?For starters, the rest of your source code in your post. If we could see your main.cpp, it would make it much easier to help.   ;  I'm only calling the functions in the main..main.cpp#include <iostream>#include "sales.h"using namespace SALES;using namespace std;int main(void) {    Sales s1;    Sales s2;   setSales(s1);    setSales(s2);   setSales(s1, s1.sales, 4);    setSales(s2, s2.sales, 4);   showSales(s1);    showSales(s2);   return 0;    };  Since you are getting linker, not compiler errors, I would assume that you are not correctly linking the object file generated by sales.cpp with your project. Code looks fine to me.[EDIT] Actually, sorry. Scrap that. The comments below are far more likely.[Edited by - EasilyConfused on June 19, 2006 4:23:51 AM];Quote:Original post by passwordI have added the using directive in the main.cpp file.The sales.cpp file also contains the header include and using directive.What am I missing?You are defining the functions inside the namespace, right? using directives isn't enough.Correct:#include "sales.h"using namespace SALES;namespace Sales{    void setSales(Sales &s, const double ar[], int n)    {}    void setSales(Sales &s)    {}    void showSales(const Sales &s)    {}}Not correct:#include "sales.h"using namespace SALES;void setSales(Sales &s, const double ar[], int n){}void setSales(Sales &s){}void showSales(const Sales &s){};  edit: too slowIn sales.cpp, where you define your funtions, are you "using namespace SALES;"?If so, thats your problem.IE, change this:#include "sales.h"using namespace SALES;void setSales(Sales &s, const double ar[], int n) {/*code here*/}void setSales(Sales &s){/*code here*/}void showSales(const Sales &s){/*code here*/}to this:#include "sales.h"void SALES::setSales(Sales &s, const double ar[], int n) {/*code here*/}void SALES::setSales(Sales &s){/*code here*/}void SALES::showSales(const Sales &s){/*code here*/};  I see..I forgot to embed the function definitions in another namespace SALES { }.Thanks   