0

This is the error I get from make:

In file included from ui/graphical/game/control/chatcommand/chatcommand.cpp:20:
ui/graphical/game/control/chatcommand/chatcommand.h:67:41: error: 
      implicit instantiation of undefined template 'cChatCommandParser<>'
        return cChatCommandParser<NewArgument>(cChatCommandParser<>(std::move(*thi...
                                               ^
ui/graphical/game/control/chatcommand/chatcommand.h:27:7: note: 
      template is declared here
class cChatCommandParser;
  ^

chatcommand.h:

...
template<typename... Arguments>
class cChatCommandParser;
...
class cChatCommand
{
public:
    ...
    template<typename NewArgument, typename... Args>
    cChatCommandParser<NewArgument> addArgument(Args&&... args);
    ...
};
template<typename NewArgument, typename... Args>
cChatCommandParser<NewArgument> cChatCommand::addArgument(Args&&... args)
{
    return cChatCommandParser<NewArgument>(cChatCommandParser<>(std::move(*this)), NewArgument(std::forward<Args>(args)...));
}

The obvious solution would be to #include chatcommandparser.h. Unfortunately chatcommandparser.h already includes chatcommand.h.

What is the most conservative way to untangle this? I don't really know what this code is doing and just want to compile it.

Note that GNUs gcc compiles this without a problem. I'm trying to compile this with Apples gcc.

user1785730
  • 3,150
  • 4
  • 27
  • 50
  • Why does `chatcommandparser.h` include `chatcommand.h`? Can you work with forward declarations on that end maybe? – Max Langhof Jul 11 '19 at 16:09
  • I think not. The class cChatCommandParser has a variable of type cChatCommand. Not a pointer. – user1785730 Jul 11 '19 at 16:12
  • The quick fix is to add `#include "chatcommandparser.h"` after the complete `class cChatCommand` definition but before the definition of its template methods. This is usually done more cleanly with a separate template implementation file (see e.g. [here](https://stackoverflow.com/questions/44774036/why-use-a-tpp-file-when-implementing-templated-functions-and-classes-defined-i)) but it's not strictly necessary. – Max Langhof Jul 11 '19 at 16:16
  • Hm.. chatcommand.ccp compiles with that, but now I'm getting the exact same error when compiling chatcommandparser.cpp. – user1785730 Jul 11 '19 at 16:21
  • Wait wait wait... There are `.cpp` files involved here? I hope you are aware of https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file?noredirect=1&lq=1, but at this point you will have to form a [mcve] before anyone can really help you. – Max Langhof Jul 11 '19 at 16:29
  • Yes, I read this hours ago. My first try actually was to move the definition in the .cpp file, which lead to problems later for reasons explained in the question you linked. – user1785730 Jul 11 '19 at 16:33
  • Why is it surprising that there are .cpp files involved? I assumed this goes without saying. – user1785730 Jul 11 '19 at 16:33
  • It is surprising because everything you showed so far must be in header files, and the whole problem _stems_ from being unable to use a .cpp for the template definitions (as you found out yourself). Again, there's no way we can help you unless you give us a minimal piece of code that reproduces the error and is representative of your issue. – Max Langhof Jul 11 '19 at 16:46

0 Answers0