Two files include each other in c++ problem
I'm doing some contribution to an open source library, but I'm having trouble modifying other people's code. Previously the library had a file called IntervalT.h
and a file called Curve开发者_开发百科s.h
with the implementation in the file Curves.tcc
, and Interval.h
includes Curves.h
for some reason. Right now I need to use IntervalT.h
in Curves.h
, but when I tried to use the class IntervalT<NT>
defined in IntervalT.h
, the compiler gives me error (I've already included IntervalT.h
in the beginning of Curves.h
file):
../../../inc/CORE/poly/Curves.h:1337:3: error: ‘IntervalT’ does not name a type
My question is: Since I never have had such experience before, is "does not name a type
" error related to mutual inclusion of c++ header files? Or it is other mistakes that cause this error? If so, how should I write my program to let the Curves.h sees IntervalT.h?
By the way, this piece of code was organized in a very weird way. Curves.tcc
is actually included by Curves.h
, which is the reverse way of we usually do. Is there a particular reason to do this? Or it doesn't really matter? And what is .tcc
extension after all?
I can only guess (because you can name your files whatever you want), but the .tcc
extension is a modification of the .cc
extension (which is just C++ code) but the t
stands for template
. This is confirmed by the fact that Curves.h
includes Curves.tcc
which is a common technique for separating the interface from the implementation of a template while still not upsetting the compiler which expects both declaration and definition of templated code in the same file (or you get an error). See this answer to get a better idea.
The does not name a type
could be that IntervalT
is a template and you're not providing a template parameter (or that could be a different error, I haven't tried it), or that even though the file is called IntervalT.h
it does not contain a class called IntervalT
, or that it's in a different namespace. You'll have to give more info before we can make a better diagnosis.
精彩评论