This topic is 4996 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

##### Share on other sites

I didn't ask for commentary about my organization, I asked if anyone could help me figure out why I was getting the errors.

##### Share on other sites
The reason why I put the functions' bodies inside of the .h files is because when I put them into .cpp files, I would get errors saying that the functions were undeclared when I try to call them in my winmain function

##### Share on other sites
this is whats happening
// h.h#ifndef H_H#define H_H#include "a.h"#include "b.h"#endif// a.h#ifndef A_H#define A_H#include "h.h"void callb(){b();}void a(){};#endif// b.h#ifndef B_H#define B_H#include "h.h"void callb(){a();}void b(){};#endif// m.cpp#include "h.h"int main(){	calla();	return 0;}

// step 1#include "h.h"int main(){	calla();	return 0;}// step 2#ifndef H_H#define H_H#include "a.h"#include "b.h"#endifint main(){	calla();	return 0;}// step 3#ifndef H_H#define H_H#ifndef A_H#define A_H#include "h.h"void callb(){b();}void a(){};#endif#ifndef B_H#define B_H#include "h.h"void callb(){a();}void b(){};#endif#endifint main(){	calla();	return 0;}// step 4#ifndef H_H#define H_H#ifndef A_H#define A_H#ifndef H_H#endifvoid callb(){b();}void a(){};#endif#ifndef B_H#define B_H#ifndef H_H#endifvoid callb(){a();}void b(){};#endif#endifint main(){	calla();	return 0;}// step 5#ifndef H_H#define H_H#ifndef A_H#define A_H#ifndef H_H#endifvoid callb(){b();} // ERROR HERE!!! undefinedvoid a(){};#endif#ifndef B_H#define B_H#ifndef H_H#endifvoid callb(){a();}void b(){};#endif#endifint main(){	calla();	return 0;}

##### Share on other sites
Whether or not you want to hear about your organization, it is likely causing the problem. With the exception of class members, defining functions in headers is a very bad idea. The only reason you can (almost) get away with it now, if I understand your situation correctly, is that you only have one .cpp file. Declare the function in the header, then define it in a .cpp file. The errors you got probably result from either 1) not including the appropriate header in the file with WinMain() in it or 2) not including the .cpp file in your project. It is not enough to simply create it, you must add it to the list of project files, as well.

Learning to properly organize multi-file projects does take some effort, but the long term benefits in terms of avoided linker errors and what-not are tremendous. I can't be sure if your poor organization is what is causing your problem yet, but certainly no one wants to try to debug what is obviously some sort of file organization issue when the organization is so messy.

##### Share on other sites

Ok. I put all of my function declarations into .h files and all of the function bodies into .cpp files. I'm still getting an error stating that the functions are not declared. I use one header file "header list.h" to contain every other .h file in it. I include "header list.h" in every .h and .cpp file.
All of my .cpp files are included into my project folder. What else could I be doing wrong?

##### Share on other sites
Quote:
 I include "header list.h" in every .h and .cpp file.

including header list.h in all .h files may be the problem
try removing

##### Share on other sites

ummm...from which file? because every one of my .h files needs the header files located in "header list.h"

##### Share on other sites
Quote:
 because every one of my .h files needs the header files located in "header list.h"

1. 1
2. 2
3. 3
4. 4
Rutin
19
5. 5

• 14
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
632926
• Total Posts
3009252
• ### Who's Online (See full list)

There are no registered users currently online

×