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
//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 :)
"::" is for defining a function that is declared inside a class (the class SALES, in this case). I don't know where did you get it from, but just get rid off it, and it should be fine ;) You just need to #include the header file of your function's declaration (as you already have) and call it simply this way:
@JCaselles - wouldn't you use the scope operator (::) also with namespaces. If he wants to use any namespace within his function he can use the scope operator to use such functions i thought, just like std::cout. I may be wrong though.
@murdok - you are linking only the .cpp files right?
@JCaselles - wouldn't you use the scope operator (::) also with namespaces. If he wants to use any namespace within his function he can use the scope operator to use such functions i thought, just like std::cout. I may be wrong though.
My bad! I didn't realize he's using namespaces! You're right. (Again, next time, you better post your code in it's dedicated format!!! ¬¬ ;)
Now, your problem is sales.cpp. This is the definition file of namespace SALES, therefore you shouldn't "use namespace SALES" but rather still define SALES, since in the header file you've only declared it, like all the functions and variables.
With only this change it should compile (compiles on mine). You have some kind of endless loop, though...