I am currently writing a program and cannot understand why I received an error message (note: I already fixed it, I wonder WHY there was an error, and what it means to include .h files).
Basically, my program was structured as follows:
In the current file I'm working with, I will name Current.cc (which is an implementation of Current.h ).
Current.cc includes a header file called CalledByCurrent.h (which has an associated implementation called CalledByCurrent.cc ). CalledByCurrent.h contains the class definition.
In CalledByCurrent.cc , called thisFunction() , a non-classical function was defined. thisFunction() not declared in CalledByCurrent.h since it was not actually a member function of the class (just a small helper function). In Current.cc I needed to use this function, so I just overridden thisFunction() at the top of Current.cc . However, when I did this, I got an error saying that the function is duplicated. Why is this when myFunction() is not even declared in CalledByCurrent.h ?
So I just deleted the function from Current.cc , now assuming that Current.cc had access to thisFunction() from CalledByCurrent.cc . However, when I did this, I found that Current.cc did not know what function I was talking about. What the heck? Then I copied the function definition for thisFunction() to the top of my CalledByCurrent.h file, and this solved the problem. Could you help me understand this behavior? In particular, why did he think that there was a duplicate, but he did not know how to use the original?
ps - I apologize for how confused this post is. Please let me know if there is anything that I can clarify.
source share