Reputation: 3327
I have implemented Customer, DVD, Receipt, classes and 2 files for main functions and menu functions, I included all the .h files, but when I use a function for example from the menu functions, it doesnt work, and says the functions isnt defined. I want to write the in a seperate .cpp file which is called main that is the driver of my application.
Here is my code:
#ifndef CUSTOMER_H
#include "Customer.h"
#endif
#ifndef DVD_H
#include "DVD.h"
#endif
#ifndef MAIN_FUNC_H
#include "MainFunctions.h"
#endif
#ifndef MENU_FUNC_H
#include "MenuFunctions.h"
#endif
#ifndef RECEIPT_H
#include "Receipt.h"
#endif
using namespace std;
int main () {
intro();
return 0;
}
and the error is:
Error 1 error C2129: static function 'void intro(void)' declared but not defined c:\program files (x86)\microsoft visual studio 10.0\vc\include\xmemory 186 1 DVD_App
even though the function intro()
is defined in the MenuFunctions.h
file, and implemented in MenuFunctions.cpp
NOTE: The 2 files, MenuFunctions and MainFunctions dont have classes in them, just static functions I also tried it without the include guards, and again didnt work
Upvotes: 0
Views: 281
Reputation: 16168
If you mark function with static
(note - function, not method), it is meant to be 'local' for the compilation unit (.cpp file). So it needs to be declared AND defined there, and is not visible from other cpp files. So, removing static means, that the function can be accessed across compilation units.
Upvotes: 2
Reputation: 317
Make sure the MenuFunctions.cpp file has
#include "MenuFunctions.h"
at the start of it. The error says it's declared, but not defined. Safeguard the #include "MenuFunctions.h"
to prevent double include.
Upvotes: 0
Reputation: 5477
You are not compiling the MenuFunctions.cpp, in order for the compiler to know the definition of the intro() it needs the implementation code. Check your makefile if you have one, if not, include MenuFunctions.cpp before main(), or specify the MenuFunctions.cpp as well to the compiler.
Upvotes: 0