Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ including a ".h" file, function duplication confusion
    text
    copied!<p>I'm currently writing a program, and couldn't figure out why I got an error (note: I already fixed it, I'm curious about WHY the error was there and what this implies about including .h files).</p> <p>Basically, my program was structured as follows:</p> <p>The current file I'm working with, I'll call <code>Current.cc</code> (which is an implementation of <code>Current.h</code>).</p> <p><code>Current.cc</code> included a header file, named <code>CalledByCurrent.h</code> (which has an associated implementation called <code>CalledByCurrent.cc</code>). <code>CalledByCurrent.h</code> contains a class definition.</p> <p>There was a non-class function defined in <code>CalledByCurrent.cc</code> called <code>thisFunction()</code>. <code>thisFunction()</code> was not declared in <code>CalledByCurrent.h</code> since it was not actually a member function of the class (just a little helper function). In <code>Current.cc</code>, I needed to use this function, so I just redefined <code>thisFunction()</code> at the top of <code>Current.cc</code>. However, when I did this, I got an error saying that the function was duplicated. Why is this, when <code>myFunction()</code> wasn't even declared in <code>CalledByCurrent.h</code>? </p> <p>Thus, I just removed the function from <code>Current.cc</code>, now assuming that <code>Current.cc</code> had access to <code>thisFunction()</code> from <code>CalledByCurrent.cc</code>. However, when I did this, I found that <code>Current.cc</code> did not know what function I was talking about. What the heck? I then copied the function definition for <code>thisFunction()</code> to the top of my <code>CalledByCurrent.h</code> file and this resolved the problem. Could you help me understand this behavior? Particularly, why would it think there was a duplicate, yet it didn't know how to use the original?</p> <p>p.s - I apologize for how confusing this post is. Please let me know if there's anything I can clear up.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload